Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Eclipse NoClassDefFoundError for external .jar files

I have come across a strange error. I have an Android project that uses external libraries, in particular:

  • android-support-v4.jar (for Fragment support in Android 1.6)
  • GoogleAdMobAdsSdk-4.3.1.jar (for ads)

The project ran fine until I updated some aspects of the plugin (can't recall the specifics as I did not pay too much attention to it) and after that, whenever I try to use any class from the above .jar files (or any of its subclasses, even ones defined by me), I would get a java.lang.NoClassDefFoundError. I could not find the answer after much searching, so I am really stumped.

I believe this problem is related to how my IDE is set up and it has little to do with actual code, so I will not post any unless if it's absolutely necessary.

like image 668
Dan Avatar asked Mar 23 '12 03:03

Dan


4 Answers

You need to read this - Dealing with dependencies in Android projects.

This link is also useful - ClassDefNotFoundError with ADT 17

Basically, create a folder called libs and place all of your jar files inside. The recent update will automatically take care of the rest for you. You don't need to edit your path anymore.

like image 119
adneal Avatar answered Nov 14 '22 02:11

adneal


Android does not support Java1.7 up to now. Jars built with compliance level 1.7 cannot be used in Android Applications. Rebuild your Java project with compliance level 5.0 or 6.0 before exporting the jar file.

I found this post via google and answers above didn't solve my problem. Hope what I say will be helpful to others.

like image 43
miaowhehe Avatar answered Nov 14 '22 03:11

miaowhehe


If you see NoClassDefFoundError after upgrading to ADT 22, try this in Eclipse:

  • Go to Project PropertiesJava Build PathOrder and Export tab.
  • Check the Android Private Libraries option.

Android Private Libraries option

like image 7
Pang Avatar answered Nov 14 '22 02:11

Pang


Also a warning to others who have updated to r17 with many dependencies. I had a another referenced project on my build path and it still did not work after following ALL the directions on this r17 issue on the internet.

Found out after an hour that my referenced project used an older version of an external Jar than my main project did. When trying to compile the main project, Eclipse would give up due to this jar version difference and I never noticed the warning message in Console.

Solution was to copy the newer version external jar file to the referenced project's libs directory.

Wow - such a productivity killer.....

like image 1
Shane Menchions Avatar answered Nov 14 '22 03:11

Shane Menchions