简体   繁体   English

引用外部Java和Android库

[英]Referencing External Java and Android Libraries

I am trying to reference a Java and an Android library (that I created) to use within my Android application built in Eclipse. 我正在尝试引用Java和Android库(由我创建),以便在Eclipse中构建的Android应用程序中使用。

I am referencing the Java library via Properties-->Java Build Path-->Projects-->Add. 我通过“属性”->“ Java构建路径”->“项目”->“添加”引用Java库。
I am referencing the Android library via Properties-->Android-->Library-->Add. 我通过属性-> Android->库->添加引用Android库。

Both of these are shown within the windows after adding them. 添加它们后,这两个都显示在窗口中。 I also moved the Java library to the top of the list within Properties-->Java Build Path-->Order and Export. 我还将Java库移到了Properties-> Java Build Path-> Order and Export列表的顶部。

My project compiles fine but when I run the application on my device I get a NoClassDefFoundError from the Java library. 我的项目编译正常,但是当我在设备上运行应用程序时,我从Java库中收到了NoClassDefFoundError。 The class is in there and should work. 班级在那里,应该工作。

Did I miss something that I need to link in order to get this running correctly? 我是否错过了需要链接才能正常运行的内容?

I am referencing the Java library via Properties-->Java Build Path-->Projects-->Add. 我通过“属性”->“ Java构建路径”->“项目”->“添加”引用Java库。

This is incorrect. 这是不正确的。 Please undo that, and then copy the JAR into libs/ within your project. 请撤消该操作,然后将JAR复制到项目中的libs/中。 If you are on the R22 or higher version of the tools, you may also need to go to "Order and Export" in your build path dialog and check "Android Private Libraries" . 如果您使用的是R22或更高版本的工具,则可能还需要在构建路径对话框中转到“订购并导出”,然后选中“ Android私有库”

What you did only added the JAR to the compile path. 您所做的只是将JAR添加到了编译路径。 Putting the JAR in libs/ will add it to the compile path and package the JAR's contents in your APK, so those classes are available at runtime. 将JAR放入libs/会将其添加到编译路径并将JAR的内容打包到您的APK中,因此这些类可在运行时使用。

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

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