I previously posted about how you could make a free and lite version of your application using the Android Library project feature inside of Eclipse.
I set out to do this a few days ago with a client project that I had been working on. My development work flow went like this:
- Build the entire app in one project first. All features.
- Turn the said app into a library
- Build out the Full and Lite shells
- Crank out the Full and Lite versions as APK’s so I can get them on the Android Market.
The Problem
However, wen I got to part 3 I ran into an issue. The Android Project would not reference the Library. However, in the gen/ folder I could see that the R.java file was being generated by Eclipse with the resources from the referenced project. However, there was no referenced project icon and anytime I added anything to the ApplicationManifest.xml file Eclipse would complain that it could not find the class.
It seemed that Eclipse ‘knew’ about the project because it could build the R.java file, but could not fully find it. It was somewhere in Eclipse limbo.
Solution
After about 6 hours of trying various things I figured out what the issue was.
The problem: My projects in Eclipse had spaces in them (note, I’ve found that periods also cause a problem).
I changed the name of my projects to not have any spaces or punctuation in them. Such as “FooLibrary” instead of “Foo Library” or “Foo.Library”. Then I de-referenced the project, then referenced it again. It still would not show up. Sometimes restarting Eclipse can make everything “bind” again. Not sure why, but it seems to be a bug with the ADT plugin. Long story short, after restarting Eclipse, the referenced project was now available and working as it should.
Note, this is only the project name in Eclipse, not the Java package name.
Conclusion
Moral of the story – don’t use spaces, periods or any punctuation in your projects or libraries if you want to use Android Library Projects.
I wish the Android Documentation had a comment system so that I could post this there as it would have saved me 6 hours and a lot of frustration because spaces in the name of a project being the root cause is not too intuitive.