3

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?

1
  • Which adt version do you use? Commented Apr 23, 2012 at 7:37

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Nope, that doesn't help too :(
Note that if the jar file generated by your java project has dependencies on other third party jar libraries, you need copy all those third party jar libraries into libs/ folder as well.
Jar file has dependencies, and I didn't have a thought that I have to copy them on libs folder too, however I've generated new test jar file without dependencies, and it doesn't work as well.
Your problem is quite popular and obvious, some jar dependencies are not dexed and built into final apk. The solution is also quite straightforward, find and locate the jar that contains the missing class, then use either one of these 3 answers we provided to include the jar dependencies, It should fix you problem.
Thanks for that, but I didn't quite get what do you mean by finding jar, that contains the missing calls? Considering LogCat output, there are only missed classes from the jar I want to include. Do you mean I should find some another jars? Could you be more specific, please.
3

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

2 Comments

I've already done 1 to 5, and now I've tried to check jar in Order tab, but it doesn't fix the issue.
after doing all the above just clean and refresh your project
0

I would go and assume you use ADT 17, there is a classpath issues with Android, you can read about it here, you just go to the Export tab and check the jar.

4 Comments

I have ADT 18 installed, didn't they fix the issue? Check the jar in export tab doesnt't help.
try adding the jar to your libs folder, and add it to the classpath without exporting it.
Do you mean select Add Jar instead of Add external Jar in configuring Bulid Path?
I know that. Moreover, I've tried both before post the question here, but i just didn't get what do you mean by "add jar to classpath without exporting it", could you explain, please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.