Multiple applications with different names for the same code base

12,185

Solution 1

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.

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

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

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.

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.

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

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

Hope this helps.

Solution 2

I had this same question. Maybe you have found the answer at this point, but some searching finally led me to this website, which explains Gradle.

It seems to explain all the basics really well. For the answer to your specific question, look for the section Product Flavors under Build Variants.

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 exactly like what you're doing.

I probably didn't explain it the best, but that website does a pretty good job.

Solution 3

The way to have multiple apps from a common code base is to have the common code as a library project, and have each app use the library project (see http://developer.android.com/tools/projects/index.html). Each project can override strings.xml, and the common come can check the package id.

In your case it seems that this is against the Google Play policy (cookie cutter apps), so it may be better to create one app and let the user choose a country.

Solution 4

For this you have to use App Localization concept. For this you have to create different resources, durables. Let say You want to run your application in japan, you have to create drawable folder like "res/drawable-ja". This is same as you create different layouts to support tablet and small devices. here is reference link: http://developer.android.com/guide/topics/resources/localization.html http://developer.android.com/distribute/googleplay/publish/localizing.html

Solution 5

I am not sure what you want exactly. But at my point of level, you can able to get the geo location, there you can find-out where you app currently running out, or in more easier get the location from locale, once you find the locale or geo-location, you can navigate the source according to that.

Share:
12,185
My God
Author by

My God

Sr. Software Engineer (Information Technology) Technologies - Ruby ON Rails, Java/J2EE, Android Development. Certifications - Sun Certified Java Programmer (SCJP) Experience - 7 years Far better is it to dare mighty things, to win glorious triumphs, even though checkered by failure... than to rank with those poor spirits who neither enjoy nor suffer much, because they live in a gray twilight that knows not victory nor defeat.

Updated on June 18, 2022

Comments

  • My God
    My God almost 2 years

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

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

    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.

    For example:

    (In many Java files, I used)

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

    (Similarly, In many Java files, I used)

    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.

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

    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.

    My question:

    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 ?

    UPDATE:

    Read this Post - multiple-android-application-package-apk-files-from-single-source-code

    Then I came up with the same idea -

    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) Have multiple AndroidManifest.xml files for multiple apps you need to create .apk for.

    3) Create corresponding launcher activities for each manifest.

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

    UPDATE:

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

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

    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.

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

    public static final String app_Name = "testApp_CANADA" ;
    

    OR

    More clearly,

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

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

  • My God
    My God over 10 years
    Thanks! Can you show me (by docs, links, etc.) that how the aforementioned lines account to be against the Google Play Policy. I read the Google Play docs viz.. play.google.com/about/developer-content-policy.html, developer.android.com/distribute/googleplay/policies/index.h‌​tml and play.google.com/about/developer-distribution-agreement.html but didn't found anything to be against of what I am trying to achieve.
  • yoah
    yoah over 10 years
    @VedPrakash I am not a lawyer. The policy is here play.google.com/about/developer-content-policy.html. The most relevant section says "Do not post repetitive content". I was once at an Android developers conference and a guy from Google mentioned a similar case to yours as an example and said to use one app instead of many. But I am not sure if this is a suggestion or a policy.
  • My God
    My God over 10 years
    Creating resources based on locality is fine. The biggest issue is how to rename the same app with different names (thus having different .apk files from single source code) based on locality and put on google play store.