简体   繁体   中英

Android: Using an old app as a library project

I'm trying to use an old app as a library project for a new app. However, there are some issues when they're both installed on the device at the same time, which I'm not sure exist after publishing.

Let's say my old app is A, new app is B.

If I just install A, A works ok.

Then when I install B, which uses A as a library project (after ticking project A as "isLibrary"), the original A stops working on the device, but B works fine.

However, if I install B first, then A, both work ok.

It seems that when A is included as a "library project" to another app, and is installed after the original "A", then the original "A" is somehow invalidated!!! (but the problem doesn't exist the other way around)

Will this problem disappear after publishing, or must I create a library project C for both A and B, which will prevent this? Or does this problem simply not exist under the circumstances described (meaning I'm doing something else wrong entirely)?

The reason why I didn't create a library project C was because of all the refactoring involved, and Eclipse doesn't do a great job of re-naming everything in my case.

Check out the official dev guide Managing Projects - Library Project :

However, a library project differs from an standard Android application project in that you cannot compile it directly to its own .apk and run it on an Android device. Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library. Instead, you must compile the library indirectly, by referencing the library in the dependent application and building that application.


Back to your question:

If I just install A, A works ok.

Because A is a Application Project (isLibrary setting un-ticked), A.apk is complied, installed and work.

Then when I install B, which uses A as a library project (after ticking project A as "isLibrary"), the original A stops working on the device, but B works fine.

A is changed to Library Project now (isLibrary setting ticked), there is no A.apk anymore at this point, only B.apk (with A compiled and merge when build B.apk) is compiled, installed and work.

However, if I install B first, then A, both work ok.

If A is a library project, IDE like Eclipse does not allow you directly compile, install and run it on Emulator or real device. I suppose you change A back to application project (isLibrary setting un-ticked) then, so A.apk is again compiled, installed and work.

It seems that when A is included as a "library project" to another app, and is installed after the original "A", then the original "A" is somehow invalidated!!! (but the problem doesn't exist the other way around)

Basically correct, check out official dev guide for detailed information.

Will this problem disappear after publishing, or must I create a library project C for both A and B, which will prevent this? Or does this problem simply not exist under the circumstances described (meaning I'm doing something else wrong entirely)?

No and Yes, you need library project C if you want to make both project A and B as application project (so that you can compile, install and run them on the emulator or real device).

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