Roy Solberg
Roy Solberg

Reputation: 19643

Building Android project to different packages

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?

Upvotes: 4

Views: 569

Answers (2)

Mr. Developerdude
Mr. Developerdude

Reputation: 9668

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.

Upvotes: 4

Jan-Terje Sørensen
Jan-Terje Sørensen

Reputation: 14698

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

Upvotes: 1

Related Questions