简体   繁体   中英

How can I get my external jar to be bundled with the Android APK?

I tried everything I found posted on Stack Overflow and yet I'm still getting the annoying NoClassDefFoundException when I try to test on the emulator:

  1. I copied the jar to the "libs" directory of the android project
  2. I added the jar to the build path using Add Jar NOT add external jar
  3. I ticked the jar in the export tab

I even tried to compile the jar once with JDK 1.6; still the same annoying exception. The jar I'm referring to just contains a few entity objects I created for another project, and would like to re-use with my Android project.

By the way, I also tried to add the jar as an external jar, but didn't work either.

You need to add it to the assets/ directory along with adding it to build path in that location for it to work. Do remember to pick the same jar when adding external library.

See this thread

NoClassDefFound Error comes in java, when some class is not available on runtime, while it was available at compile time, please check what is source of this error, you can use following blog to get assistance:

http://javarevisited.blogspot.in/2011/06/noclassdeffounderror-exception-in.html

Do the following ::

Go to the project properties >> Java Build Path add jar file as external jar.

Select order and export option >> select the libraries and jars of the project.

If not working change the order of jar make sure its above android dependencies .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM