Android Library Project Reference Not Showing

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:

  1. Build the entire app in one project first. All features.
  2. Turn the said app into a library
  3. Build out the Full and Lite shells
  4. 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.

  • Wolfgang Korn

    Interesting! I'm having exactly the same problem. But I do not have any spaces, periods or so in my project names. And also restarting Eclipse did not solve the problem. Still looking for a solution :-(

  • Wolfgang Korn

    It seems that I was a little bit too impatient. After a couple of Eclipse restarts, removing and re-importing the application project, the library showed up in the application project and all build errors were gone. It looks like there is some room for improvement handling the libraries.

  • Findnilam

    Hi,

    I can't see android folder in eclipse.. any solutions.. i tried downloading eclipse 3.5 stil not working?

  • http://www.google.com/profiles/safrany.zsolt Safi

    Hi there,

    I had exactly the same problem. Had a library “dev-common”, and an app “game-X”.
    I renamed the folders to “devcommon” and to “gameX” and also did the same renaming in the .project files (@projectDescriptionname).

    Then I did a de-reference and then a re-reference. Restarted eclipse and then it worked: Source folders of “devcommon” were linked to “gameX” and my app could finally compile.

    I have
    Version: Helios Release
    Build id: 20100617-1415

    p.s.: thanks for the post!

  • Guest

    Replacing “-” by “_” works as well.
    (I noticed that the library project “com_android_vending_licensing” was working while my own library was not.)
    Eclipse Helios, ADT 0.9.7
    Thanks so much!

  • Herbrandson

    Thank you!

  • Marlon Hendred

    This also seems to occur if your library has dashes in it (ie my-library). To fix I renamed the library project with no dashes. Then I restarted eclipse and then re-added the library to the main project and it then it finally showed up! Hope this helps.

  • Rishabh Sethi

    Hi
    even after creating a repository in eclipse 3.6 – m not able to see Android folder in windows -> preferences in Eclipse.

  • http://hqessay.com/ college paper writing service

    Really site is made for business. In the search engines find the site is not difficult – very promoted. Constantly updated news feed company.

  • http://www.facebook.com/gregmil Greg Milette

    Hi,

    None of this worked. What I had to do was:

    Create a new workspace. I made sure to set the Android SDK before I reloaded all my projects.

    Enjoy.

  • http://blog.donnfelker.com Donn Felker

    Sorry it did not work for you!

  • Zestyspike

    Thanks for this article I will try to resolve my problem with these steps also. I have had nothing but problems trying to set up shared/common code. Why is such a fundamental feature so darn clumsy? I can’t even use winmerge because every code file includes the package name meaning that all code files show as different?! Why can’t you specify a activity in the manifest that isn’t in the typical namespace. You can’t move it to a parent or child level.

  • James Patillo

    +1 for a comment system on the docs. I like the feature on MSDN.

  • Coach Outlet Online
  • Coach Factory Outlet