同一代码库具有不同名称的多个应用程序 [英] Multiple applications with different names for the same code base

查看:23
本文介绍了同一代码库具有不同名称的多个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读这篇文章,认为有同样的问题 - 一个代码库,两个应用程序安卓

Reading this article, thought having the same problem - One code base, two applications on Android

我创建了一个应用程序 testApp,其中包含 topicssplash screenlogos 等项目>chartsrulesstatuses 和/或 events.

I have created an application testApp that has items like topics, splash screens, logos, charts, rules, statuses and/or events.

现在,我想要来自相同代码库的不同应用程序(testApp_USAtestApp_CanadatestApp_Australia)并将它们放在 Google Play 商店中如果用户下载应用程序,例如,testApp_USA,那么只应显示该地区的特定项目,如美国的启动画面、美国徽标等.

Now, I want different applications (testApp_USA, testApp_Canada, testApp_Australia)from the same code base and put them on Google Play Store so that if user downloads the application, say, testApp_USA, then only the specific items to that region should be shown like splash Screen of USA, USA logos, etc..

所以我想根据国家/地区配置多个应用程序,然后根据用户下载的应用程序将项目设置为默认值.

So I want to configure multiple applications according to countries and then set the items as defaults according to which application the user has downloaded.

目前,我有一个适用于所有地区的应用程序,我根据地区强加了多个条件来区分或更改项目.

Presently, I have a single application which is for all regions and I am imposing multiple conditions to distinguish or change the items according to the regions.

例如:

(在许多 Java 文件中,我使用了)

if(rule.contains("USA"))
{
 //Show splash screen of USA
}

(同样,在很多 Java 文件中,我使用了)

if(rule.contains("Australia"))
{
 //Show splash screen of Australia
}

这只是贯穿整个代码的许多重复项目中的一项.综合考虑,会更多.

This is just a one item out of many repeated throughout code. Considering all, it will be lot more.

应该有更好的方法在 android 中创建多个具有不同名称和设置的应用程序.

There should be a better way to create multiple applications in android with different names and settings.

我知道,iOS 允许我轻松更改应用程序名称和配置文件以允许创建多个应用程序.但是我不知道或者这在Android代码上不容易做到.

I know, iOS allows me to easily change the application name and profile to allow multiple apps to be created. But I don't know or this is not easy to do on the Android code.

我的问题:

是否可以在 android 中使用相同的源代码创建具有不同项目设置的不同应用程序并将它们发布到 Google Play 商店?如果YES,如何设置这样的配置?

Is it possible to create different applications with the same source code in android with different settings of items and publish them to Google Play Store ? If YES, How to set such configuration ?

更新:

阅读这篇文章 - multiple-android-application-package-apk-files-from-single-source-code

然后我想出了同样的想法-

Then I came up with the same idea -

1) 获取一些字符串变量,其中包含有关您要创建的应用程序类型的值.

1) Taking some string variable that holds values about which application type you want to create.

public static final String app_Name = "testApp_CANADA" ;

2) 有多个 AndroidManifest.xml 文件用于您需要为其创建 .apk 的多个应用程序.

2) Have multiple AndroidManifest.xml files for multiple apps you need to create .apk for.

3) 为每个清单创建相应的启动器活动.

3) Create corresponding launcher activities for each manifest.

但是如何在单个应用中拥有多个 AndroidManifest.xml 文件?

But then how to have multiple AndroidManifest.xml files in a single app ?

更新:

我的第一个 AndroidManifest.xml 像往常一样位于 主项目 文件夹(应用程序根文件夹)中.为 testApp_USA 考虑这个.

My first AndroidManifest.xml is in main project folder (application root folder) as usual that we have. Consider this for testApp_USA.

我的第二个AndroidManifest.xml 位于主项目下的单独包中.为 testApp_CANADA 考虑这个.

My second AndroidManifest.xml is in separate package under main project. Consider this for testApp_CANADA.

两个 AndroidManifest.xml 都有不同的启动器活动,并定义了相应的启动画面和图标.两者的包名称不同,因此它们会根据需要创建不同的 .apk 文件.

Both AndroidManifest.xml have different launcher activities with corresponding splash screens, icons defined. The package names are given different in both so that they will create different .apk files as per requirement.

现在,如果我的主应用程序有设置,如何在 testApp_USA/testApp_CANADA 之间切换代码:

Now, how to switch code between testApp_USA/testApp_CANADA provided my main app has setting:

public static final String app_Name = "testApp_CANADA" ;

更清楚,

如何根据app_Name的值调用特定的AndroidManifest.xml?

How to call a particular AndroidManifest.xml according to the value of app_Name ?

根据我目前的设置,只有第一个 AndroidManifest.xml 总是被调用.

With the current setup that I have, only first AndroidManifest.xml is called always.

推荐答案

我在将项目投放到不同市场时遇到了类似的问题 - Google Play、Samsung、Amazon.所有代码库都相同,区别仅在于计费代码.

I had similar problem with putting project to different markets - Google Play, Samsung, Amazon. All code base is the same, difference only in billing code.

我发现的最佳解决方案是为每个市场创建单独的项目并将通用代码推送到库项目中.

The best solution I found is creating separate project for each market and pushing common code into library project.

更详细地说,您需要在主项目中保留通用代码,使其成为库项目并为库和子项目启用清单合并.在主项目的 project.properties 中添加以下几行:

In more detail, you need to leave common code in main project, make it library project and enable manifest merger for library and child projects. Add following lines to project.properties of main project:

android.library=true
manifestmerger.enabled=true

这对每个子项目的 project.properties :

and this to project.properties of every child project:

android.library.reference.1=../testApp //absolute or relative path to your main project
manifestmerger.enabled=true

此外,您还需要将主项目作为 ADT 插件中的库(在 Eclipse - 项目属性 -> Android 中)附加到所有子项目.主项目清单不应包含任何启动器活动,它将被忽略,与 appWidget xml 和配置活动相同,如果您有的话.

Also you need to attach main project as library in ADT plugin (in Eclipse - project properties -> Android) to all child projects. Main project manifest should not contain any launcher activity, it will be ignored, same thing with appWidget xml's and config activities, if you have some.

在子项目中,您可以配置任何您想要的内容,并通过扩展或仅使用所需的类作为普通 Java 库来使用主代码.此外,您可以使用主要项目活动、服务、广播接收器等,就像它们在您的子项目中一样,而无需任何子项目清单的重复.配置完成后,您可以像往常一样为所需的国家/地区构建所需的项目,就像通常的单个项目一样,您可以根据需要为不同的国家/地区提供不同的 apk.

In child projects you can configure whatever you want and use main code by extending or just using needed classes as normal Java library. Also, you can use main project activities, services, broadcast receivers, etc just as they are in your child project without any duplication of manifest of child projects. After all configured, you can just build needed project for needed country as usual single project and you would have different apk's for different countries, as you want.

这里是清单合并的更详细说明http://www.platoevolved.com/blog/programming/android/merging-android-manifest-files/

Here is more detail description of manifest merging http://www.platoevolved.com/blog/programming/android/merging-android-manifest-files/

请注意,此功能已在 ADT 版本 20 预览版 3 中添加.

Note, this feature was added in ADT version 20 preview 3.

希望这会有所帮助.

这篇关于同一代码库具有不同名称的多个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆