Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you inject build-specific configuration into an APK?

I have an Android app which I distribute to several different market providers; the app is functionally the same for each, but requires certain distinct configuration parameters. Ideally I would like to produce all the individual APKs in one build step. Is there an "official" way to achieve this?

I am considering an approach in which I have a template file in the project structure, and at build time use ant to interpolate values into an output file such as res/xml/config.xml.

Thanks in advance!

like image 503
Thomas H Avatar asked Jul 16 '10 23:07

Thomas H


People also ask

How do I make an APK file?

To generate a signed APK file, open the Build menu from the toolbar and select Generate Signed Bundle/APK. This opens up a screen where you have to select between creating an Android App Bundle and creating an APK file. Check the APK radio button and proceed to the next window.

What is configured APK?

What is the Config APK Android app? It is the OS package responsible for the automatic installation and uninstallation of third-party apps. It takes up to 20KB of space and is hidden with your other system apps.

What is build process in Android?

The build process involves many tools and processes that convert your project into an Android Application Package (APK) or Android App Bundle (AAB). The build process is very flexible, so it's useful to understand some of what is happening under the hood.


1 Answers

There are a couple ways to approach this:

1) Setup an Android Library Application (designed for Eclipse)

This is the method suggested in the Android documentation. With this method, you would setup your application to be a "Library Project".

Then, for each specific build you would like to produce, you would setup a new Android project that references the previously created Library Project. This project would need to have its own AndroidManifest which declares the components used from the library application. Since each application has its own manifest, almost any type of customization can be made by swapping out components or changing information. However, while allowing for complex differences, this does create some redundancy in maintenance if there is few differences.

2) Built an ANT script or other build script to manipulate the configuration

An ANT script could at build time manipulate the sources or XML files to allow for custom configuration. The easiest way to do this would be use the unix sed or a python/ruby script to do the customization. This is ideal where the customization is limited to small changes and/or just textual replacements. This is my route of choice in most cases.

I recommend copying the source tree to a temporary directory prior to making the manipulations such that it can be cleared on an "ant clean" and will not affect the working copy of the source.

One warning with this is that I would design the modifications such that the source still builds without running the script (i.e. so you can do standard builds while developing in eclipse or any other environment without requiring the special script to run).

like image 101
Rajiv Makhijani Avatar answered Oct 05 '22 12:10

Rajiv Makhijani