简体   繁体   English

Android:使用旧版应用程式做为图书馆专案

[英]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. 假设我的旧应用是A,新应用是B。

If I just install A, A works ok. 如果我只安装A,A可以正常工作。

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. 然后,当我安装B(将A用作库项目)(将项目A标记为“ isLibrary”之后)时,原始的A停止在设备上工作,但是B可以正常工作。

However, if I install B first, then A, both work ok. 但是,如果我先安装B,然后再安装A,两者都可以。

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!!! 看来,当A作为另一个应用程序的“库项目”被包含并在原始“ A”之后安装时,原始的“ A”就会以某种方式失效! (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? 发布后此问题会消失,还是必须同时为A和B创建一个库项目C,这样可以防止这种情况? 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. 我之所以没有创建库项目C的原因是因为涉及到所有的重构,而在我的案例中Eclipse并没有很好地重命名所有内容。

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. 但是,库项目与标准Android应用程序项目的不同之处在于,您无法将其直接编译为自己的.apk并在Android设备上运行。 Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library. 同样,您不能像真正的库那样将库项目导出到独立的JAR文件中。 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. 如果我只安装A,A可以正常工作。

Because A is a Application Project (isLibrary setting un-ticked), A.apk is complied, installed and work. 由于A是一个应用程序项目(未选中isLibrary设置),因此A.apk得以编译,安装和运行。

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. 然后,当我安装B(将A用作库项目)(将项目A标记为“ isLibrary”之后)时,原始的A停止在设备上工作,但是B可以正常工作。

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. 现在将A更改为Library Project(将isLibrary设置选中),此时不再有A.apk,只有B.apk(在构建B.apk时已编译并合并)才被编译,安装和工作。

However, if I install B first, then A, both work ok. 但是,如果我先安装B,然后再安装A,两者都可以。

If A is a library project, IDE like Eclipse does not allow you directly compile, install and run it on Emulator or real device. 如果A是一个库项目,则类似Eclipse的IDE不允许您直接在Emulator或真实设备上编译,安装和运行它。 I suppose you change A back to application project (isLibrary setting un-ticked) then, so A.apk is again compiled, installed and work. 我想您然后将A更改回应用程序项目(未选中isLibrary设置),因此A.apk再次被编译,安装和工作。

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!!! 看来,当A作为另一个应用程序的“库项目”被包含并在原始“ A”之后安装时,原始的“ A”就会以某种方式失效! (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? 发布后此问题会消失,还是必须同时为A和B创建一个库项目C,这样可以防止这种情况? 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). 否,是,如果要将项目A和B都设为应用程序项目,则需要库项目C(以便可以在仿真器或真实设备上编译,安装和运行它们)。

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

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