4

I'm trying to find the best way to build/package an Android app for 6+ different customers. I could use different branches in SVN for all of the customers, but the only difference between the apps are some values in the resource folder (drawables, strings, etc).

I wrote an ant script that imports the standard Android build.xml. This script does the following:

  1. Reads the customer names from a properties file.
  2. For each customer the following is done:
    1. The package name in AndroidManifest.xml is changed (by hooking into the -pre-build target).
    2. The custom resources are copied into the res directory in the build (by hooking into the -pre-compile target).
    3. The package name is changed back to the default value (by hooking into the -post-compile target).
    4. The APK is copied to a specific location an named something like customer-versionno.apk.

This seemed to work well until I just now wrote the part that changes the package name. Because of the package name change the location of the R class is also changed, meaning that the build fails as the Java classes import the R class from the standard package.

I don't want to have a build script that changes code. I want to be able to do this with minimum changes to any files.

Soo..the questions are really:

  1. Are there any good/simple solutions for my problem?
  2. Am I approaching this problem in the wrong way? Are there better ways to easily package the same app to 6+ different customers?
Roy Solberg
  • 18,133
  • 12
  • 49
  • 76

2 Answers2

4

Do you really need to change the package name? Changing the package name is a pain to do automatically. That being said, here is my solution to the problem:

My scenario is that I have one app that gets deployed to 30-200 different signed APK files where the only difference between the files are some resources (drawables, strings, values etc), and the package name.

I do this by working on a generic version of the app that serves as the template project. Once this works and I am ready to deploy I invoke a bash script that loops through the following steps for each target:

  1. Clean the project completely
  2. Swap out res dir and package name using sed.
  3. Builds and signs the APK

This balances the horrific deply time with fast developemnt time. I really don't see another more elegant/robust solution than this.

And finally a small tip: In android manifest use relative package names like ".Application" instead of "com.mycompany.myproject.Application". This way you only need to change the package name in ONE location.

Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
  • If you are not into bash I would suggest using a scriptable build tool such as SBT (which also have a plugin for ANT). Then you can script the hold build process using Scala. – Zapodot Mar 21 '12 at 09:09
1

Is it possible to solve this with making 6+ different projects that includes your main projekt. This way you are able to override resources and make different apk's

Jan-Terje Sørensen
  • 14,468
  • 8
  • 37
  • 37
  • This is indeed possible. And all the customer projects would not need much attention/work. However, I would like being able to have a one click build and not having that many projects in my IDE just for a relatively small app. – Roy Solberg Mar 21 '12 at 08:46
  • Looking back at this today I think this is the best solution. – Roy Solberg May 22 '13 at 08:01