Matt
Matt

Reputation: 95

Android:jar library won't work compared to project library

I'm getting stuck with android library stuff.

I have

This jokerly lib is a graphical library using views, xml, pics, and generated files (eg R.java).

I manage to start my app without any problems with the import of the jokerly lib (the project) in properties/android/library. Everything works fine - here is the pic :

!Eclipse screenshot android library

On the other hand, when I try to import the jokerly.jar (and removing the jokerly lib project from the same place as above) in the java build path, I've got a classNotFound Exception, whatever the state of the checkbox and the position of the jokerly.jar in the properties/javabuildpath/order and export. I also tried to put it in the libs folder manually, but the problem is the same.

Eclipse screenshot javabuildpath

Eclipse screen shot order and export

java.lang.RuntimeException: Unable to instantiate application com.example.testphilippe.Jokerly: java.lang.ClassNotFoundException: Didn't find class "com.example.testphilippe.Jokerly" on path: DexPathList[[zip file "/data/app/com.example.testphilippe-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.testphilippe-2, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:509)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4417)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.testphilippe.Jokerly" on path: DexPathList[[zip file "/data/app/com.example.testphilippe-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.testphilippe-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newApplication(Instrumentation.java:975)
at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
09-11 11:13:37.350: E/AndroidRuntime(22080):    ... 11 more

I tried (according to @Vj_Droid advice) some more manips :
I added the jokerly.jar in the java build path (not in the lib folder) from outside the project. I have the same error if the check box is not checked. If I check it, I have the following error. If I add the jokerly.jar manually in the libs folder and then add it into the javabuild paht from the libs folder, I have thee same error (below) even if the box is unchecked.

[2013-09-11 11:59:42 - TestPhilippe] Error generating final archive: Found duplicate file for APK: AndroidManifest.xml
Origin 1: /Users/markelys/Dropbox/Tech/Projets/Android/Workspace/TestPhilippe/bin/resources.ap_
Origin 2: /Users/markelys/Dropbox/Tech/Projets/Android/Workspace/jokerly.jar

Here is what i did for exporting the Jar file : Eclipse Jar Export Eclipse Jar Export 2

Feel free to ask more information if you need it !

I've got stuck on it for severals days... Any help will be appreciated !

Upvotes: 3

Views: 1256

Answers (2)

Matt
Matt

Reputation: 95

According to the Android Doc found in @TactMayers's link (Thanks !), it is not possible for now :

However, a library project differs from a standard Android application project in that you cannot compile it directly to its own .apk and run it on an Android device. Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library. Instead, you must compile the library indirectly, by referencing the library in the dependent application and building that application.

The point seems to be the resources and manifest, and everything that is note pure java code. Typically views, xml, and so on. It seems that there is some planning to add this kind of support, but it does definitely not exist right now.

So if anybody have more information about that, and updates about ADK team creating a thing for that, that would be nice !

Thanks for everybody's help !

Upvotes: 3

k3b
k3b

Reputation: 14755

 > Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.testphilippe.Jokerly" ... 

In page "Order and Export" your jar is not marked as "copy this jar into the android-apk" so the classloader cannot find it. Set the checkmark and "ClassNotFoundException" will go away.

Upvotes: 0

Related Questions