I am building an Android app in Eclipse and have two similar apps based on the same code base, a ‘London’ one and a ‘UK’ one. To build each app, I just re-name the main package and change a static int in the Application class. The app uses the value of this int to display the right UI, restrict user behaviour, etc.
I have two icon files, one for each app:
- res/drawable-hdpi/icon_london.png
- res/drawable-hdpi/icon_uk.png
Is there any way to conditionally use the correct icon file for the Application and Activities depending upon some sort of project configuration setting? Otherwise, the project maintenance is increased as I would have to change my manifest each time the code base changes, e.g.
<application
android:icon="@drawable/icon_london"
...
>
<activity
android:name="com.company.MainActivity"
android:logo="@drawable/icon_london"
>
</activity>
…and so on, for all the activities.
I had a similar issue, and ended up in building my custon Ant script to build the apps. You can run macros or Regular Expressions to assign one resource or another.
EDIT:
First, add build.xml to the project:
Open up a command prompt and navigate to the directory of your project:
Then, you can override the existing build.xml, for something like the following.
NOTE: This Ant script is just an example, I have not tested it:
Then, to build this project with a custom icon, open up the command prompt and go to the project directory:
As said, this is a very basic example. To build a good script, you’ll have to learn a bit of Ant syntax, but it’s not difficult.