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.)

Leave a Comment