Android Eclipse NoClassDefFoundError for external .jar files
Asked Answered
E

7

15

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.

Ectype answered 23/3, 2012 at 3:0 Comment(0)
G
35

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.

Gristmill answered 23/3, 2012 at 3:4 Comment(1)
I really don't know why they changed ADT to behave this way as these libraries will be shared between several projects. But at least this will be a short-term fix.Ectype
P
7

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.

Periosteum answered 29/3, 2013 at 11:8 Comment(1)
This turned out to be my problem. I recompiled with 1.6 and voila! I used "javac -source 6 -target 6 ..."Drove
O
7

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

Open answered 27/5, 2013 at 3:46 Comment(0)
L
1

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.....

Locale answered 30/3, 2012 at 21:30 Comment(0)
S
0

I ran into this error today too, because of updating to the Android SDK, r17. What the links that @aneal pointed out do not discuss is how to handle external runtime libraries (such as those imported under their own heading - not an imported user library).

The easiest way to solve this problem is to change the build order in the build path. Simply right click on your project and select Properties. From here, select Java Build Path. At the top of the display, choose the tab order and export and move GoogleAdMobAdsSdk-4.3.1.jar above Android X (replacing x with the version you are using). Next, clean your project and run it. You should be good to go!

Shrub answered 23/3, 2012 at 5:47 Comment(0)
C
0

The way I solved it was by : Right clicking on the project and selecting build path. Select configure build path in the selections that appear. After that see if your libraries are there in the libraries folder and then select the order and export tab and over there select all your jar files. Then select ok and run your project.

Chiropractic answered 17/5, 2013 at 9:22 Comment(0)
F
0

If you're using Eclipse with Maven IDE (m2e) go to "Java Build Path" then "Order and Export" and finally check the item "Maven Dependencies" and pull it down to the BOTTOM of the list. You should do the same with project references in the same workspace. Every time I setup the project in a new computer that happens.

Flutterboard answered 14/6, 2014 at 10:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.