相同的项目但可以定制并可以一起安装?
我有一个小型 Android 项目,用作核心项目。从这个核心项目中,我希望能够进行定制。
所以我有使用标准图标、按钮等的框架格式的应用程序...我希望能够使用不同的图标和按钮创建不同的版本。
这我知道该怎么做。 (我将有两个单独的 apk 文件,两者都具有相同的代码但具有不同的资源)
但是我希望能够同时在同一设备上安装核心项目和自定义项目。目前,其中一个将覆盖另一个。
我尝试更改清单中的包,但这反过来意味着我还必须更改 Java 文件中 R.java 的所有导入,这是我想避免的事情。
是否可以仅更改 xml 中的某些内容,从而允许我有两个使用相同 Java 文件但具有不同资源的项目?
I have a small Android project that I use as a core project. From this core project I want to be able to do customisations.
So I have the app in a framework format using standard icons, buttons etc... I want to be able to create different versions with different icons and buttons.
This I know how to do. (I will have two separate apk files, both with the same code but with different resources)
However I want to be able to install the core project and a customisation on the same device at the same time. Currently one will overwrite the other.
I have tried to change the package in the manifest but this in turn means I would have to also change all the imports for R.java in my Java files, this is something I want to avoid.
Is it possible to change just something in xml that will allow me to have two projects using the same Java files but with different resources?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用 Android 库。
将所有应用程序代码放入一个 Android 库中,然后创建两个具有自定义图标和不同包名称的 Android 应用程序。最终 Android 应用程序中定义的资源将覆盖 Android 库中所有已存在的资源。
一个缺点是:您的 Android 应用程序中需要有几乎相同的
AndroidManifest.xml
文件副本(但它们仍然应该具有不同的包名称)。有关详细信息:
You should use Android Libraries.
Put all your application code into one Android Library and then create two Android Applications which have custom icons and different package names. The resources defined in final Android Applications will override all already existing resources in Android Library.
One drawback: you'll need to have to almost identical copies of
AndroidManifest.xml
files in your Android Application (but they still should have different package names).For more info:
您应该创建一个包含所有源代码的库项目,并为引用该库项目的每个可安装包创建一个项目。然后,您可以定义/覆盖可安装项目中的任何资源定义
You should create a library project that contains all of your source code, and create a project for each of your installable packages that references the library project. You can then define/override any resource definitions in the installable projects