Android Library Project - can't find class from library project at runtime?
I'm trying to create an android library project so I can make a lite and full version of my app with shared code. Following the directions here:
http://developer.android.com/guide/developing/projects/projects-eclipse.html
http://blog.donnfelker.com/2010/08/05/howto-android-full-and-lite-versions/
Running my lite version throws a ClassNotFoundException at runtime because it cannot find the activity class from the shared project. It's as if the project linking (properties -> java build path -> projects -> add) isn't actually including any of the .class files at runtime.
Anyone else running into this problem? I don't want to export a .jar from my library project because with this other method we can share activities and such which is ideal. The manifest of my "lite" project, which references the library project activity:
<application
android:name="com.me.test.lib.App">
<activity
android:name="com.me.test.lib.ActivityMain" >
It can't find either the App class or the ActivityMain class which are part of the library project.
Thanks
The exception - the path in the ComponentInfo look开发者_运维技巧s wrong, should it be nested like that?
04-29 16:49:01.759: ERROR/AndroidRuntime(2349):
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{
com.me.test.lite/com.me.test.lib.ActivityMain}:
java.lang.ClassNotFoundException: com.me.test.lib.ActivityMain
in loader dalvik.system.PathClassLoader[/data/app/com.me.test.lite-2.apk]
I had this problem when trying to access the Activity in my toolkit library. Make sure project using the library puts any Activities in its own Manifest. The toolkit doesn't actually specify Activities in its Manifest. It sounds like you did that part right. Linking the library for android projects is different from java projects.
For the library project
Right click the Eclipse project, select Properties. Go to the Android tab. Check the box that says "Is Library"
For application using the library
Right click the Eclipse project, select Properties. Go to the Android tab. Add the library project as a reference
精彩评论