简体   繁体   English

可能的Android项目取决于其他(非库)Android项目?

[英]Possible Android project depends of other (non library) Android project?

I have apps A and B . 我有应用程序AB I want one to use some methods A in B . 我希望在B使用一些方法A Is that possible? 那可能吗?

I tried adding project A to the build path of B. Compiler is OK with that, but I get runtime NoClassDefFoundError (for the first used class from project A ). 我尝试将项目A添加到B的构建路径。编译器就可以了,但我得到运行时NoClassDefFoundError (对于项目A第一个使用的类)。

I'm making this with Eclipse. 我是用Eclipse制作的。

Edit: The reason I need to to that is because my project B is a test of project A. It was not possible to test the usual way, because between other things I have to test AsynchTasks, and that doesn't work with JUnit. 编辑:我需要的原因是因为我的项目B是项目A的测试。不可能测试通常的方式,因为在其他事情之间我必须测试AsynchTasks,这不适用于JUnit。 So I thought making normal Android project B containing custom test. 所以我认为制作包含自定义测试的普通Android项目B. But since that also doesn't seem to work, I came back to my original test project and implemented there my custom / not JUnit tests. 但由于这似乎也没有用,我回到原来的测试项目并在那里实现了我的自定义/非JUnit测试。 In an ugly way, but it works. 以一种丑陋的方式,但它的工作原理。

What you are describing is a Library Project . 您所描述的是图书馆计划 If you have source code and resources that are common to multiple Android projects, you can move them to a library project so that it is easier to maintain across applications and versions. 如果您拥有多个Android项目通用的源代码和资源,则可以将它们移动到库项目,以便更容易跨应用程序和版本进行维护。 Thus, if you are developing multiple related applications that use some of the same components, you would move the redundant components out of their respective application projects and create a single, re-useable set of the same components in a separate library project. 因此,如果要开发使用某些相同组件的多个相关应用程序,则可以将冗余组件移出其各自的应用程序项目,并在单独的库项目中创建一组可重用的相同组件。

Thus, what you are describing is almost possible, but not quite. 因此,你所描述的几乎是可能的,但并不完全。 Eclipse doesn't let you reference Android application projects (ie projects that compile to a .apk file) as library projects, so simply making project A a library project and having B reference A won't work. Eclipse不允许您将Android应用程序项目(即编译为.apk文件的项目)作为库项目引用,因此简单地将项目A作为库项目并使用B引用A将不起作用。 Instead, you will need to, 相反,你需要,

  1. Create a new library project C . 创建一个新的库项目C
  2. Move the common methods/classes from projects A and B to library project C . 将公共方法/类从项目AB到库项目C
  3. Have both A and B reference library project C . 同时拥有AB 参考库项目C

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

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