简体   繁体   English

如何将我的外部jar与Android APK捆绑在一起?

[英]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: 我尝试了所有在Stack Overflow上发布的内容,但是尝试在模拟器上进行测试时,仍然遇到了令人讨厌的NoClassDefFoundException

  1. I copied the jar to the "libs" directory of the android project 我将jar复制到android项目的“ libs”目录中
  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; 我什至试图用JDK 1.6编译jar。 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. 我指的jar仅包含我为另一个项目创建的一些实体对象,并且希望与我的Android项目一起使用。

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. 您需要将其添加到assets/目录,并添加它到该位置的构建路径才能使其正常工作。 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: Java中出现NoClassDefFound错误,当某些类在运行时不可用,而在编译时可用时,请检查此错误的根源,您可以使用以下博客获取帮助:

http://javarevisited.blogspot.in/2011/06/noclassdeffounderror-exception-in.html 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. 转到项目属性>> Java构建路径,将jar文件添加为外部jar。

Select order and export option >> select the libraries and jars of the project. 选择订单和导出选项>>选择项目的库和jar。

If not working change the order of jar make sure its above android dependencies . 如果不起作用,请更改jar的顺序,确保其高于android依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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