0

I know that there are some similar questions, but no solution helped me. I am getting a java.lang.NoClassDefFoundError when I try to access an (existing) class in a self-created .jar from my projectgroup.

This .jar works fine in an normal javaProject but doesn´t work with Android. But an older version of this .jar worked fine with Android.

I am developing with Eclipse + Android Development Tool - Plugin (Version 21) I have put the .jar in the Project_Home/libs folder. There are no errors at compiletime.

Before the exception was thrown, there was some "dalvikvm - could not find class ... referenced from ..." errors.

I think, there could be a problem with the Java Version, because our projectgroup recently started to use Java 7, but I am not sure and have no idea how to fix it.

Thanks a lot for your help.

user2212120
  • 287
  • 1
  • 2
  • 9
  • Have you updated your build path? – Cornholio Mar 26 '13 at 15:26
  • 1
    You basically should check Build Path or Project-Properties-Android if you need to add it as a library. – Roman Mar 26 '13 at 15:29
  • @Cornholio: I think you don't have to add it to the buildPath, when you place it into the libs folder. But I've tried it multiple times - doesn't work – user2212120 Mar 26 '13 at 15:59
  • @user2212120: the way I've done it before, you need to place it in your libs folder, and then right click in Package Explorer, and click on Build Path -> Configure Build Path. From there, click the Libraries tab and click add JAR. Then add the JAR and it should work fine. – Cornholio Mar 26 '13 at 16:02
  • @Roman: Yes I have. But you are right: It sounds like a BuildPath problem. Or a Problem with dalvikvm I think. I´ve added and removed it to the buildpath several times - but nothing helped. – user2212120 Mar 26 '13 at 16:03
  • @Cornholio: I have done it like you have described a lot of times - no success. – user2212120 Mar 26 '13 at 16:05
  • @user2212120: Then I'm not sure what the issue is - Good luck. – Cornholio Mar 26 '13 at 16:06

4 Answers4

0

Rename your lib to libs and update the build path and then try again

Rohit
  • 1,001
  • 1
  • 11
  • 20
0
  1. Make sure that your classes do not have same names as ones already present within Android. Upon building the package, due to "optimization" classes with same names are omitted.

  2. Android libraries are mostly compiled against 1.5. Not all libraries are also present within Android. Your package may depend on some other library that is not present within the system.

Joel Bodega
  • 644
  • 5
  • 8
  • 1.: It is a unique name. I don't want to print it hear, but it is about 50 characters long - and nothing like example.org – user2212120 Mar 26 '13 at 16:09
  • 2.: It could be, but an older version of this .jar worked fine. There were no big changes and now it does not find any class in the .jar – user2212120 Mar 26 '13 at 16:11
0

I think if the project is compiling fine then we can rule out any error in copying or java buildpath. The only other time i get this error is when my import is wrong in the code. I would suggest you to re-check your import and recreate R.java file.

Parvaz Bhaskar
  • 1,367
  • 9
  • 29
  • What exactly you mean with "re-check import" (delete all imports and import it again?). – user2212120 Mar 26 '13 at 16:18
  • yes i meant that please make sure that the import that you are doing is the right jar that you want to import. check the package name..you mentioned that the previous jar worked so it might be referencing the old import. – Parvaz Bhaskar Mar 26 '13 at 17:09
  • yes, it is the right jar. I have deleted the input and there was only one import possibility from the right jar. The old jar I deleted. – user2212120 Mar 26 '13 at 17:17
  • do you have any other project dependencies? sometimes the order of import matters, check the order of imports from build path and check if unchecked.. may be move some other dependent project to top and jar to lower down hierarchy – Parvaz Bhaskar Mar 26 '13 at 17:28
  • Good idea, no luck: I only use the jar. Of course the Android 4.2 and Android Dependencies are listed, too. the jar is on top. – user2212120 Mar 26 '13 at 17:41
  • I am running out of ideas can you post a stack trace? – Parvaz Bhaskar Mar 26 '13 at 18:11
  • try moving down the jar and let the dependencies load first, and select(tick) for import if not selected(unchecked). – Parvaz Bhaskar Mar 26 '13 at 18:24
  • I have probably found the cause, but dont now how to solve it: The Console print out an other warning, which I did not see before: Dx bad class file magic (cafebabe) or version (0033.0000) this seems to be an hint, that the compilation level is wrong (I had this suspicion before, compiled with Java 7). The solution should be to set the Compilation level to 6 how explained here [link] http://stackoverflow.com/questions/7866723/dx-bad-class-file-magic-cafebabe-or-version-0033-0000-with-adk14 but my projectgroup has decided to migrate to java 7 - what can I do? – user2212120 Mar 26 '13 at 18:38
  • you can look into migration guides and changes made with java 7. Since this is project specific question I cannot help you there nor do I have an idea of how to migrate since I never did it myself. – Parvaz Bhaskar Mar 26 '13 at 18:54
  • Thanks, I think I have to resolve this with my projectmanager. – user2212120 Mar 26 '13 at 18:58
0

Ordinarily I don't want to answer my own question but I hope it will help someone.
I didn't see an other warning (not in Logcat, it was in the console):

"Dx bad class file magic (cafebabe) or version (0033.0000)"

I had found this Warning in an other Stackoverflow question. I had opened one of the class file from the not working .jar with an HexEditor and changed the Major-Version-Byte to 0x32 and it worked. I know this is not a solution, because there could be features from Java 7 in the class, so the class file no longer work, but it proves that it was a problem with the Java version

Community
  • 1
  • 1
user2212120
  • 287
  • 1
  • 2
  • 9