Android - Multiple Custom Versions of The Same App

Android – multiple custom versions of the same app

Perhaps the built-in Android "library" concept was not fully baked at the time of the original post, but it may be the preferred method as of 2011. Follow these steps for an ant build:

Starting from a working app (let's call it directory "myOrigApp", package com.foo.myapp), just add this line to "default.properties" to make it a library:

android.library=true

Now create a new app in a sibling directory in any way you prefer (let's call it directory "sibling", package com.foo.myVariant). Using Intellij Idea, for example, create a project 'from scratch' with directory 'sibling' and it will create all the files/directories you would normally need.

In that new, sibling directory edit "default.properties" to add the dependency:

android.library.reference.1=../myOrigApp

Copy over the Manifest from the original dir:

cd sibling
cp ../myOrigApp/AndroidManifest.xml ../myOrigApp/local.properties ../myOrigApp/build.properties .

Edit that copied Manifest file to change its package name to your new variant, "com.foo.myVarient"; that's the only change.

If you just run the ant build scripts, you may be done. (I had to just set up signing keys.)

If you want to set up an IDE like Idea to have the library project as a dependent of the variant project, follow these steps to add a library project to the variant project (assumes you already have a project set up for both):

  • Open the original project, bring up Project Settings, select your Facet and check "Is Library Project" and save.
  • Open the variant project, bring up Project Settings, select Modules
  • Add a module
  • Select “Import existing module”
  • Browse to the Original directory (myOrigApp) and select its .iml file (IntelliJ project source file)
  • Click "Finish." (The library project is added as a module within the variant project.)
  • In the modules list click over the Variant project to select it.
  • On the right hand side select the "Dependencies" tab.
  • Click "Add…"
  • Choose "Module dependency…" (A list should appear that includes the name of the module/library you previously added to the project--perhaps the only entry in the list).
  • Select the library project you added and press OK. (It will be added to the list of dependencies of your project.)
  • Press OK to finish configuring the project. (You should see 2 modules, with the library's resources and classes available and recognized in the Variant project.)

Creating multiple custom versions of the same android app

Thanks to the comment of Nimish Choudhary and more Google the answer to my problem was that I have to make unique all Activity names for to the 2 Apps.

So in the AndroidManifest.xml I have change all the names of all the Activities, i.e.:

     <activity
android:name="app1.vcMainScreen"
android:label="@string/title_activity_home"
android:screenOrientation="portrait"
android:launchMode="standard" >
<intent-filter>
<action android:name="app1.vcMainScreen" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

And I change the return of the switch when I was calling the function:

    Util.getController(buttons
.getJSONObject(arg2)
.getString("ViewController")

Now the return is:

    switch (Integer.parseInt(num)) {
case 0:
return "app1.vcMainScreen";
default:
return null;
}

I hope this help someone one day.

Thanks to all.

How to Organize Android App with Multiple Versions of Assets

Gradle Build Variants allow you to have a shared main codebase/resources and multiple variants with custom resources/code associated with each - you then can generate a separate APK for each variant. Of course, using Gradle for Android development requires you use Android Studio (which is currently in beta) as well.

Release several android applications with same code base

You need to create a library project and reference it from every of your apps. Latest versions of ADT plugin allow this. Go to the project properties, android page, you'll see a 'library' checkmark there. Reference to the library is also setup on the page.



Related Topics



Leave a reply



Submit