3

I'm getting stuck with android library stuff.

I have

  • a project dedicated for the library (let's call it jokerly).
  • a project with the application (let's call it testPhilippe)
  • a jar generated from the lib (let's call it jokerly.jar)

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 !

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
Matt
  • 95
  • 1
  • 11
  • i guess its a library project so you cannot add it as a jar. you need to reference the same – Raghunandan Sep 11 '13 at 09:31
  • Did you add the jar to the build path after putting it in the libs folder? – Simon Sep 11 '13 at 09:34
  • Thanks Hovanessyan ;) i add the pic right now. Raghunandan : The point is that we do not want to release the code, but only a jar. @Simon : Yes, i added it in the libs folder, then added it in the java build path, and tested top and bottom for checked and unchecked box. – Matt Sep 11 '13 at 09:38
  • Just select Checkbox of "Jokerly.jar" in "Order and Export" of Java Build path. – Vj_droider 웃 Sep 11 '13 at 09:48
  • I added an edit to the post @Vj_droider웃 because i do not have enough space here :) – Matt Sep 11 '13 at 10:00
  • In reply to "Yes, i added it in the libs folder, then added it in the java build path...", you don't need to add the jar into java build path manually. It's already included under the "Android Private Library" group. You can click the arrow on the left of "Android Private Library" to verify it. – TactMayers Sep 11 '13 at 10:04
  • @TactMayers Ok, so i assume that it is the reason for the new error i'm getting (duplicate ressources) ? Adding it not in the libs, but only from the java build path fields do add it in the Android Referenced Libraries (directly in the project explorer). In the properties, i do find the jar but not under Private Library (it is at the same level, above). – Matt Sep 11 '13 at 10:07
  • In reply to new edit: Remove the 'AndroidMainfest.xml' from your jar file and the error should be gone. – TactMayers Sep 11 '13 at 10:07
  • @TactMayers : i tryed to do it simply while exporting, but it does not work for now. I post the images describing the export of the jar. – Matt Sep 11 '13 at 10:11
  • And just to make sure, the jokerly library project does not contain any resources file, just java classes, right? – TactMayers Sep 11 '13 at 10:11
  • I think it actually do. It is a library that uses views, so i assume that it do need some of these ressources ? I updated the manifest according to what our devs told us. – Matt Sep 11 '13 at 10:13
  • @Matt did you add any resources files (XML layout/images) into your library project and make use of them in the library? More precisely, did you library project code contains any reference to the R.java generated inside the library project? – TactMayers Sep 11 '13 at 10:19
  • There is definitely an R.java generated, at least R.string.smthing, R.id.wbview and R.menu.activity_web_view are used in the .java of the lib. There are severals others. We do use images and xml layouts (views) in the library, defined in the library. – Matt Sep 11 '13 at 10:25
  • In that case you may need to take extra steps. Refer to answers of this SO question: http://stackoverflow.com/questions/9868546/android-how-to-export-jar-with-resources – TactMayers Sep 11 '13 at 10:41
  • @TactMayers thanks for that, this is very usefull ! We will work on that now. I still have a question : we did manage to make that thing work before, without particular steps. It refused to work only since yesterday without anything special from us (we think.. The only thing could be an update of ADT) :( – Matt Sep 11 '13 at 12:24
  • See also : http://stackoverflow.com/questions/18419425/java-servlet-project-and-android-library-project-in-eclipse-noclassdeffounderr/18594605#18594605 – Mr_and_Mrs_D Nov 11 '13 at 20:07

2 Answers2

3

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 !

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
Matt
  • 95
  • 1
  • 11
0
 > 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.

k3b
  • 14,517
  • 7
  • 53
  • 85
  • Hi, Thanks for your time. I already tested that, and i had 2 differents problems after that. Either the duplicate ressource problem, either the noclassdeffound error. Both are described in the post. – Matt Sep 11 '13 at 12:37
  • thanks for answering your own question (+1). This answer could be the reason why my current-private-apk-project does not compile. I check this when i am home. – k3b Sep 11 '13 at 14:51