Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Android Application Package .apk files from single source code

Tags:

android

apk

ant

I would like an Android build system procedure, command line or Eclipse, to generate several .apk files from a single source codebase. Some common reasons for this - having specific versions for markets with different requirements or a free and paid version.

This question IS NOT ABOUT:

  • Packaging shared code into Android libraries or into external Java jars

  • Producing a debug vs. signed release .apk

Google says "you probably need to create separate Android projects for each APK you intend to publish so that you can appropriately develop them separately. You can do this by simply duplicating your existing project and give it a new name." Then they kindly suggest using libraries, which I understand. Then, they mention in passing exactly what I do want: "a build system that can output different resources based on the build configuration"

  • I know that to accomplish conditional compilation in JAVA one can key off a 'public static final' variable. There is an example of tweaking such a value in build.xml. Any more complete example of an Android Ant build configuration for this or a link to an OSS project doing that now, please? BTW, build.xml is auto-generated, but I have seen people hacking it, so how does that work?

  • With the package name declared in Manifest.xml as package="com.example.appname", if one needs to emit multiple .apks that vary that name, is one stuck with a separate project for each?

like image 662
Walter K Avatar asked Sep 21 '11 23:09

Walter K


People also ask

What are APK splits?

Apk splits allow app developers to divide (split) their apks across device densities and Application Binary Interfaces (ABIs). These separate apks are uploaded to Google play store and users only get to download the right and optimized apks for their device.

What is the difference between AAB and APK?

Basically, AAB is a publishing format that a developer submits to the Play Store while APK is the packaging format for Android apps that you install on your device.

What do Android Package .APK files contain?

To make an APK file, a program for Android is first compiled using a tool such as Android Studio or Visual Studio and then all of its parts are packaged into one container file. An APK file contains all of a program's code (such as .dex files), resources, assets, certificates, and manifest file.

Can APK file be shared?

However you can send APK files using other Android Apps via email, Google drive etc. Use Easy APK Sharer - Android Apps on Google Play to share APK files. no ways, you need to share that via some apk share app like 'share-it' or 'xender'.


1 Answers

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

like image 159
Barmaley Avatar answered Sep 23 '22 20:09

Barmaley