I followed some steps I found here (can’t find the URL right now, sorry) to convert my Android project in Eclipse to a layout where 99.9% of my code is in a library project, and then I have 2 other shell projects under the same workspace that are mostly just the AndroidManifest.xml files, and a few resource files. This was done so I can support 2 builds of the same project, with just some minor text/icon changes between the 2. The application name is also different so I can publish both on the Android Market at the same time.
Ever since I did this, about every 10 times I compile, maybe once every day or two, I get “dalvik error 1” and something about “Access already exists” (Access being the name of the first Java unit in my library project).
To “work around” the issue I go in to the Java Build path for my stub-project that I am trying to build, and remove the JAR file from my main library from the libraries tab. Then I can build without the error.
Then a while later (maybe 1 or 2 days) I’ll get an error about missing classes when I compile my stub-project (not my library). So I’ll go back to the Java Build path and put the reference to the JAR file back in, and all is good again for 1 or 2 days, then I’m back to the same error as before.
Is this just a known issue and something I need to do, or can I resolve by a restructure of my projects/workspaces? Currently I have:
Lib Project – only has 2 libs on build path: Android 2.1 and com.android.ide.eclipse.adt.LIBRARIES
First stub project that uses above lib – has the same 2 libs as above project, plus sometimes I use “Add JAR” to include the JAR from the above project’s bin\ folder.
2nd stub project – same libs as first stub project
Should I reference the JAR from my “lib project” using one of the other tabs under build path options? Maybe the “Project” tab instead, or the “Source” tab? I don’t currently have it under any of those other areas.
When I get in to the weird state, doing a “Clean project” also doesn’t help, I’ve tried that several times and open/close the IDE between cleaning, to no resolve.
At this point we are in the final testing stages, so my normal daily task is:
-
Make a minor update (bug fix) in the LIB project
-
Use the publish wizard to export both projects and update Android Market and other places we keep the APK files
So I’d like those steps to stay simple, without having to open/close multiple workspaces or go through a lot of build steps if possible.
The classical Eclipse/Java way
Add a (workspace) library
Properties.Java Build Path.Librariestab.Now, it depends how you compile your library.
So either do an
Add JARs...or anAdd Class Folder.Choose the
externalvariant to use an external source.That’s it.
Add a workspace project
Properties.Java Build Path.Projectstab.Click
Add...on the right side and you are done.The additional Android way
Two steps are necessary:
Mark the library project
Right click your project and select
Properties.Select
Androidon the left and tick the checkboxIsLibrary. Done.Reference the marked project
Right click your project and select
Properties.Select
Androidon the left andAdd...your marked project. It will be added to the list and is ready to use. Now you are able to access all classes and ressources (e.g. drawables, strings) from the referenced, marked project. Awesome, eh? 🙂