Using Ant, you can customize the project by copying the template resource file or the template java file, which will be generated before launching the release target of the standard android Ant file.
Generated files should be ignored before version control.
Here is an example of Ant target that needs to be called before creating an application with an Ant release. It generates one java file and one resource file:
<target name="updateMyConfiguration"">
<copy file="./MyTemplateConfiguration.java"
tofile="./src/com/mycompany/android/myapp/MyCodeConfiguration.java"
overwrite="true">
</copy>
<replace file="./src/com/mycompany/android/myapp/MyCodeConfiguration.java">
<replacefilter token="token_my_boolean"
value="${code.configuration.my_boolean}" />
<replacefilter token="token_my_integer"
value="${code.configuration.my_integer}" />
<replacefilter token="token_my_string"
value="${code.configuration.my_string}" />
</replace>
<copy file="./MyTemplateRes.xml"
tofile="./res/values/MyResConfiguration.xml"
overwrite="true">
</copy>
<replace file="./res/values/MyResConfiguration.xml">
<replacefilter token="token_my_string"
value="${res.configuration.my_string}" />
<replacefilter token="token_my_integer"
value="${res_configuration.my_integer}" />
</replace>
</target>
package com.mycompany.android.myapp;
public final class MyCodeConfiguration
{
static final boolean my_boolean = token_my_boolean;
static final String my_string = "token_my_string";
static final int my_integer = token_my_integer;
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<add-resource type="string" name="my_string"/>
<string name="my_string">token_my_string</string>
<add-resource type="integer" name="my_integer"/>
<integer name="my_integer">token_my_integer</integer>
</resources>
Then you just need to run Ant as follows:
ant updateMyConfiguration -Dres.configuration.string=MyCustomBuildString -Dcode.configuration.my_integer=1234
source
share