Build multiple (test/prod) versions of Android APKs in Eclipse Build multiple (test/prod) versions of Android APKs in Eclipse android android

Build multiple (test/prod) versions of Android APKs in Eclipse


I think using ant build script would be the easiest solution. Eclipse supports ant build, so you can run ant command in eclipse.

You can solve your problem with ant like this.

  1. prepare two xml android resource file.
  2. build a package with resource #1
  3. overwrite resource #1 with content of resource #2
  4. build another package

xml would be like this:

resource #1:

<resources>    <string name="target">dev</string></resources>

resource #2:

<resources>    <string name="target">staging</string></resources>

and ant script would be like this:

<project>  <target name="build_all">     <copy file="res1.xml" to="res/values/target.xml"/>     <ant antfile="build.xml" target="debug"/>     <copy file="res2.xml" to="res/values/target.xml"/>     <ant antfile="build.xml" target="debug"/>  </target></project>


Move all you code to a library project see http://developer.android.com/guide/developing/projects/projects-eclipse.html#SettingUpLibraryProject

Then create separate projects in eclipse for test and production each with a unique package name. You can then use the package name to distinguish between versions.

Something like:

public static boolean isProductionVersion(){  return context.getPackageName().toLowerCase().contains("production");}

This may seem like overkill for managing different http end points but it will make the code more manageable. You can also do useful things like:

  • flag the test version with a different application icon
  • run test and production versions side by side on one device

This can all be done in eclipse without using and third party tools.


Its not really what you want:

private static Boolean isSignedWithDebugKey = null;    protected boolean signedWithDebug() {        if(isSignedWithDebugKey == null) {            PackageManager pm = getPackageManager();            try {                PackageInfo pi = pm.getPackageInfo(getPackageName(), 0);                isSignedWithDebugKey = (pi.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;            }            catch(NameNotFoundException nnfe) {                nnfe.printStackTrace();                isSignedWithDebugKey = false;            }        }        return isSignedWithDebugKey;    }

You could then hit a dev/staging server if the app is signed with a debug key, and production with a release certificate.