Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding external jar to android project

I have the following issue:

I have two projects: jre1.7 and android 2.1. I'd like to build first as a jar file and use it as framework in the second project. I'm using eclipse and I've done things I usually do when I add external jar. (Right Click on Project - Build Path - Add external Jars), and seems like everything's fine, there are Referenced libraries folder appears and it contains jar.

But when I'm trying to compile Android project, it gives NoClassDefFound Error. Am I doing something wrong?

like image 812
mol Avatar asked Aug 04 '26 01:08

mol


1 Answers

If you use Android SDK & ADT r17 or later, now Google recommended way of adding dependencies is:

  1. Create libs/ folder under project root folder.
  2. Put all dependencies jar into libs/ folder.

Android SDK now automatically pick up and resolve dependencies for you, and you don't need other manual setup anymore (add jar to project build path). Check out the r17 changelog:

Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)

In addition, It is not explicitly stated in official dev guide that Android now fully support java 7, it is better to stay with JDK 6 at the moment.

Hope this helps.

like image 137
yorkw Avatar answered Aug 06 '26 14:08

yorkw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!