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.
Solution 1:
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.
Solution 2:
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.