I want to build the android project from command line. Usually, I build the project for two environments(merchant and production) and I want to do that for Merchant and Production URL automatically from command line, without me specifying in the project manually everytime. For example Say, Build a project for Production environment or say, build a project for merchant environment by specifying the environment in command itself. Can it be done? Please help.
You can build your project with Maven, Ant and Gradle. All of them will do what you want.
I use Maven therefore I'll focus on Maven configuration. It might be a complex task if you don't know how Maven works.
First prerequisites described here:
https://code.google.com/p/maven-android-plugin/wiki/GettingStarted
Configure your project to build with android maven plugin:
https://code.google.com/p/maven-android-plugin/
Sample configuration for Eclipse:
https://code.google.com/p/maven-android-plugin/wiki/QuickStartForEclipseProject
You can also generate sample project with the command below:
mvn archetype:generate \
-DarchetypeArtifactId=android-quickstart \
-DarchetypeGroupId=de.akquinet.android.archetypes \
-DarchetypeVersion=1.0.8 \
-DgroupId=com.myproject \
-DartifactId=my-android-application
Second step is create build profiles for production.
IMPORTANT: the following profile snippet bases works pom.xml generated with command mvn archetype:generate
command above.
The profile listed below replaces string in file located in res/values/strings.xml
form:
<string name="hello">Whatever text</string>
to:
<string name="hello">productionURL</string>
The profile (include it in pom.xml above </project>
):
<profiles>
<profile>
<id>production</id>
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.basedir}/res/values/strings.xml</file>
<regex>true</regex>
<replacements>
<replacement>
<token><![CDATA[(<string name="hello">)(.+)(</string>)]]></token>
<value><![CDATA[$1productionURL$3]]></value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<sign>
<debug>true</debug>
</sign>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
It uses https://code.google.com/p/maven-replacer-plugin/ to replace string.
For Merchant just copy-paste <profile>
listed above, change <id>production</id>
to <id>merchant</id>
and in <value>
update url.
mvn install -Pproduction
or
mvn install -Pmerchant
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With