Montag, 18. Februar 2013

Build your Android App with shell commands

Build your Android app with shell commands for continuous integration tools like Jenkins

Google offers a very smoth way to build your android apk's with shell commands and ant task. These four steps will guide you to get a signed apk in no-time for test distribution.
We at impac use those steps in nightly jenkins jobs which builds our android apps for our continuous integration process.


Prerequisite
  • Installed Android SDK's
  • Installed Android Targets (e.g. 4.0.3, 4.2, ......)
  • Buildable Android App Projekt

1. Create the keystore (if you don't allready have one)

keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
Above command creates the keystore file. You have to follow the prompts in your shell to complete the keygen process. We will use this file later to sign the android apk. You only have to generate the keystore file once.

2. Create the build.xml file

android update project --target <TARGET> --path <PATH> --subprojects
The update project command creates the "build.xml" file which includes all the build informations for the "ant" process. You can specify the <TARGET> version (Android Version) .To list all your installed <TARGET> versions you can call 

android list target

You need to add your project location <PATH>

3. Build the APK with ANT

ant release -Dkey.store=<KEYSTORE-FILE> -Dkey.alias=<KEYSTORE-ALIAS> -Dkey.alias.password=<KEYALIAS-PWD> -Dkey.store.password=<KEYSTORE-PWD>
This ant command builds your apk and signs it with your keystore made in step 1. You could also build a unsigned debug version with "ant debug".
On our release command you have to set the four properties for the keystore.

4. Deliver your APK to testers


The "ant" command creates the "apk" in the "bin/" folder of your project. You can now move your APK to a website or send it via email to your testers.

You could now create a Jenkins job with the steps 2-4 and trigger the job to version control commits. This gives you the possibility to always share your newest build to testers. Step 1 is only needed once and should not be located in a jenkins job.



Keine Kommentare:

Kommentar veröffentlichen