简体   繁体   中英

Possible Android project depends of other (non library) Android project?

I have apps A and B . I want one to use some methods A in B . 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 ).

I'm making this with 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. So I thought making normal Android project B containing custom test. 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. 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. 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. Instead, you will need to,

  1. Create a new library project C .
  2. Move the common methods/classes from projects A and B to library project C .
  3. Have both A and B reference library project C .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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