简体   繁体   English

Android:如何从Eclipse ADT应用程序项目引用库项目?

[英]Android: How to reference a library project from an Eclipse ADT application project?

I have a project that is compiles but throws a NoClassDefFoundError on a classname included from a sibling library project, but only when built from Eclipse. 我有一个编译的项目,但是在兄弟库项目中包含的类名上抛出NoClassDefFoundError,但仅限于从Eclipse构建时。 When I build the project from the ant file, it runs just fine. 当我从ant文件构建项目时,它运行得很好。

How do I tell the Eclipse build system that my application's .apk needs a copy of the .class files from the library project. 如何告诉Eclipse构建系统我的应用程序的.apk需要库项目中的.class文件的副本。

This page... http://developer.android.com/guide/developing/eclipse-adt.html#libraryReference makes is sound like adding the library should "just work" with no other steps. 这个页面... http://developer.android.com/guide/developing/eclipse-adt.html#libraryReference make听起来像添加库应该“正常工作”而没有其他步骤。 And I see it has updated my default.properties with the necessary link that makes my ant build work. 我看到它已经更新了我的default.properties,其中包含使我的ant构建工作的必要链接。

Despite following those steps (my library project is listed in the Android page of my application's project properties), Eclipse doesn't recognize the new classes in the editor. 尽管遵循这些步骤(我的库项目列在我的应用程序的项目属性的Android页面中),但Eclipse无法识别编辑器中的新类。 So I did the standard Eclipse step of adding the library to the Java Build Path. 所以我做了标准的Eclipse步骤,将库添加到Java Build Path。 Now the compiler and IDE recognize the class, but my app still crashes with NoClassDefFoundError, even after checking the library in the Java Build Path, Order and Export. 现在编译器和IDE识别该类,但是我的应用程序仍然在NoClassDefFoundError崩溃,即使在Java Build Path,Order和Export中检查库之后也是如此。

What step am I missing? 我错过了什么步骤?

Some background... I built the Eclipse project first. 一些背景......我首先构建了Eclipse项目。 Then, in a separate directory, I used android create project ... with all the parameters to create an identically configured project. 然后,在一个单独的目录中,我使用android create project ...使用所有参数来创建一个相同配置的项目。 Finally, I copied the ant build.xml and *.properties files to the Eclipse project directory. 最后,我将ant build.xml和* .properties文件复制到Eclipse项目目录中。 I did the same thing with the library project I'm trying to reference. 我对我试图引用的库项目做了同样的事情。

I have this every once in a while and not sure what causes it. 我每隔一段时间都有这个,不知道是什么导致它。 To fix this, I have to link to the source of my library projects. 要解决这个问题,我必须链接到我的库项目的源代码。 In the build path of your main project, link to the "src" folder of your library project that you are trying to include. 在主项目的构建路径中,链接到您尝试包含的库项目的“src”文件夹。

We had the same issue (worked in IntelliJ and with Ant but not with Eclipse.) There was an installation of Aptana Studio installed in Eclipse. 我们遇到了同样的问题(在IntelliJ和Ant中工作但在Eclipse中没有。)在Eclipse中安装了Aptana Studio。 Removing that allowed the library project reference to work in Eclipse as advertised. 删除它允许库项目引用在广告中在Eclipse中工作。

1) Right click on your Android project. 1)右键单击您的Android项目。

2) Go to its properties 2)转到它的属性

3) Choose Android option from the menu displayed on the left 3)从左侧显示的菜单中选择Android选项

4) See the library panel which is on the right side, below the list of APIs. 4)请参阅API列表右侧的库面板。

5) Click the "Add.." button to add the library project. 5)单击“添加..”按钮添加库项目。

Keep in mind that the seperate project you are trying to add as a ibrary for your current project should be marked as "IsLibrary". 请记住,您尝试添加为当前项目的ibrary的单独项目应标记为“IsLibrary”。

I got similar a issue. 我遇到了类似的问题。 Even after adding a library project the required files were not included. 即使在添加库项目之后,也不包括所需的文件。 It seems there is a bug as discussed in this thread . 看来这个帖子中讨论的是一个bug。

I found that in Eclipse's default.properties file the library project location was not being read because my working project was in a different drive than library project (I was doing the development in Windows). 我发现在Eclipse的default.properties文件中没有读取库项目位置,因为我的工作项目与库项目不同(我在Windows中进行开发)。 After moving my project to same drive as library project it started working. 将项目移动到与库项目相同的驱动器后,它开始工作。 This might work as a work around till the bug is fixed. 这可能是一个解决方法,直到修复bug。

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

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