Android - 来自单个代码库的多个 .apk 文件
我在 android 中开发了 3 个应用程序,它们的主要功能是相同的,但 UI 看起来不同。屏幕的图像和背景颜色不同。
现在,我想创建一个代码库,从中我可以为 3 个应用程序生成多个 .apk 文件。
我尝试为 3 个应用程序的 src 文件夹创建 3 个不同的包。但我不知道如何为这些应用程序设置 res 文件夹。
需要有关创建单个代码库的指导,我们可以从中生成多个 .apk 文件,其中仅包含各自的 src 和 res 文件夹。
I had developed 3 applications in android where the major functionalities are the same but the UI looks different. Images and the background color of the screens are different.
NOw, i want to create a single code base from which i can generate multiple .apk files for the 3 apps.
I tried creating 3 different packages for src folder for the 3 apps. But i dont know how to set the res folder for these apps.
Need pointers on creating a single code base from which we can generate multiple .apk files which includes only the respective src and res folders.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为最好的选择是使用
ant
,您需要为每个构建添加一个 ant 目标并更改资源文件夹。如果使用生成的build.xml,则res文件夹定义如下
因此您需要覆盖它i think the best option is to use
ant
, you'll need to add an ant target for each build and change the resource folder.if you use the generated build.xml, the res folder is defined like this
<property name="resource.absolute.dir" location="res" />
so you'll want to override that难道您不能将所有通用代码放入一个库项目中,然后仅从 3 个包含相关资源的独特项目中的每一个中引用该项目吗?
更新:使用 Gradle 构建系统时,此答案现已过时。
Can't you put all of your common code into a library project and then just reference that project from each of the 3 unique projects that each contain the relevant resources.
Update: This answer is now obsolete when using the Gradle build system.
为什么不使用单个应用程序,该应用程序根据用户设置的 SharedPreferences 值或安装时的上下文执行三项不同的操作。如果您确实想分开,则可以拥有三个不同的活动,然后决定从重定向到其中一个不同活动的静默主活动中启动哪个活动。
另一种方法是拥有一个独特的 Activity,该 Activity 在
onCreate
时动态地从 3 个不同的布局中自行扩展。它将使代码维护更容易(只需修改一个代码源,只需维护一个版本列表和变更集)
请查看此处:
如何在 Android 中使用 SharedPreferences 来存储、获取和编辑值
Why don't you use a single application, that does three different things based on SharedPreferences values set by the user, or from context at install time. If you really want to separate, you can have three different activities, and you decide which one to launch from a silent main Activity that redirects to either of the different ones.
An alternative is to have a unique activity that inflates itself dynamically from 3 different layouts at
onCreate
time.It will make code maintenance easier (only one code source to modify, only one version-list and changeset to maintain)
Check here:
How to use SharedPreferences in Android to store, fetch and edit values
我建议使用
Gradle
口味。它似乎很好地解释了所有基础知识。我今天刚刚完成向
Gradle
的转换,效果非常好。自定义应用程序图标、名称和字符串等。正如网站所解释的,这种设计背后的部分目的是使其更加动态,并且更容易允许使用基本相同的代码创建多个 APK,这听起来与您的类似正在做。
另请参阅最近的问题 我参考了您的项目结构并为每个应用程序使用了自定义代码。
I would suggest using
Gradle
flavors.It seems to explain all the basics really well. I just finished converting to
Gradle
today, and it works great. Custom app icons, names, and strings, etc.As the website explains, part of the purpose behind this design was to make it more dynamic and more easily allow multiple APKs to be created with essentially the same code, which sounds similar what you're doing.
Also see a recent question I had, referring to your project structure and using custom code for each app.