Adding external jar to android project

12,347

Solution 1

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.

Solution 2

If you want to include this external jar into your Android project, then you just do the following steps in your Eclipse environment.

  1. Right click on your project in the project's panel.
  2. Select “Properties” option.
  3. In the Properties window, Click on “Java Build Path”.
  4. In the right side of that window, select “Libraries” tab.
  5. Click on “Add External JARs” button and add this library where you have saved previously.
  6. Now click on “Order and Export” tab and check on “JarName.jar”
  7. Click on “Ok”.
Share:
12,347
mol
Author by

mol

Updated on June 04, 2022

Comments

  • mol
    mol almost 2 years

    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?