将 Android 库项目添加到 Eclipse 构建路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16968153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding Android library project to Eclipse build path?
提问by Bevor
I have a multi module Android Maven project which consists of several projects and an Android library project (baselib) where I run non Android based JUnit tests.
我有一个多模块 Android Maven 项目,它由几个项目和一个 Android 库项目 (baselib) 组成,我在其中运行非基于 Android 的 JUnit 测试。
This works as long as I run the test by Maven. When I run the baselib JUnit tests by Eclipse with Run->As JUnit test, I don't get the current version. That means that changes in the JUnit test have no effect until I make a Maven build.
只要我通过 Maven 运行测试,这就会起作用。当我通过 Eclipse 使用 Run->As JUnit 测试运行 baselib JUnit 测试时,我没有得到当前版本。这意味着在我进行 Maven 构建之前,JUnit 测试中的更改无效。
I thought about adding the bin folder to the Eclipse build path, but I get an error message in Eclipse:
我想过将bin文件夹添加到Eclipse构建路径中,但在Eclipse中收到错误消息:
Cannot nest output folder ...baselib-TRUNK/bin/classes inside ...baselib-TRUNK/bin
无法在 ...baselib-TRUNK/bin 中嵌套输出文件夹 ...baselib-TRUNK/bin/classes
That's somehow clear. So I thought about adding the jar itself to the build path. I added it once as external jar, then once as jar. But I still don't get the current version of the code although the timestamp of the jar has the current version if I modify and save some code. (Build Automatically is checked in Eclipse). Output folder is recognized by Eclipse's build path configuration as .../bin/classes which is set in pom.xml. I also tried to add /bin/test-classesto build path which contains the test class itself, but still no new version of the code.
这在某种程度上是清楚的。所以我考虑将 jar 本身添加到构建路径中。我将它作为外部 jar 添加一次,然后作为 jar 添加一次。但是我仍然没有得到代码的当前版本,尽管如果我修改并保存一些代码,jar 的时间戳具有当前版本。(在 Eclipse 中选中自动构建)。输出文件夹被 Eclipse 的构建路径配置识别为 .../bin/classes,在 pom.xml 中设置。我还尝试添加/bin/test-classes来构建包含测试类本身的路径,但仍然没有新版本的代码。
Why does this not work to get the current version and how can I solve this?
为什么这不能获得当前版本,我该如何解决这个问题?
回答by JorganPubshire
Since the library projects are in the same workspace, we can reference the project directly. Open the preferences for your project and click on the "Android" section.
由于库项目在同一个工作空间,我们可以直接引用该项目。打开项目的首选项,然后单击“Android”部分。
Now, you will see a window for referencing library projects.
现在,您将看到一个用于引用库项目的窗口。
Click the "Add..." button, select the projects you want, click "OK", and hit "Apply". Only projects that are marked as libraries can be selected and referenced in this manner. If your projects are not appearing, open their preferences and mark the "Is Library" box in this window of their preferences.
单击“添加...”按钮,选择所需的项目,单击“确定”,然后单击“应用”。只能以这种方式选择和引用标记为库的项目。如果您的项目没有出现,请打开他们的首选项并在他们的首选项窗口中标记“是库”框。
Your project will now reference these libraries, including any changes you make to them. This is better than using a jar if your libraries will be subject to change. Otherwise, you would have to remove and re-add the jar every time you make a change.
您的项目现在将引用这些库,包括您对它们所做的任何更改。如果您的库可能会发生变化,这比使用 jar 更好。否则,每次进行更改时,您都必须删除并重新添加 jar。