Multiple Android Application Package .apk files from single source code Multiple Android Application Package .apk files from single source code android android

Multiple Android Application Package .apk files from single source code


I'm generating 2 different APK's (demo and production) from one single source tree with 3 small modifications:

1) I have public static final DEMO=true; //false; in my Application class and depending on that value I used to switch code between demo/production features

2) There are 2 main activities, like:

package mypackage;public class MyProduction extends Activity {    //blah-blah}package mypackage.demo;public class MyDemoActivity extends mypackage.MyProductionActivity{    //blah-blah}

3) And in the end 2 separate AndroidManifest.xml files which points to different launcher activities depending on demo/production switch

I'm switching between 2 APK's manually, but see nothing difficult in writing small ANT task to switch between them automatically


One way to do it would be to maintain two separate AndroidManifest.xml, one for each configuration. You can switch back and forth between the two either manually (copying) or automatically (build script).

[edit] This person here has a system to do this kind of thing: http://blog.elsdoerfer.name/2010/04/29/android-build-multiple-versions-of-a-project/


The answer to this screams Gradle, as explained on this website. It's officially built into Android Studio and is encouraged.

It's amazing; I've built 3 separate apps using the same source code, with customized text and graphics, with no special coding whatsoever. Just some directory and Gradle setup is required, and other posts of mine can be found with answers to both.

It seems to explain all the basics really well. For the answer to your specific question, look for the section Product Flavors under Build Variants, where it describes specifying different flavors.

As the website explains, part of the purpose behind this design was to make it more dynamic and more easily allow multiple APKs to be created with essentially the same code, which sounds exactly like what you're doing.

I probably didn't explain it the best, but that website does a pretty good job.