Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Sunday, April 15, 2012

Automatic Android Release Builds with CI

So if you are using a CI server (eg. Hudson aka Jenkins) to build your Android app, when you come to release it you'll want to do that automatically too.

All thats required is this kind of stanza in your build.xml:

<property environment="env"/>
<target name="-post-build" >
        <copy todir="bin">
            <fileset dir="bin">
                 <include name="myappname-*.apk"/>
            </fileset>

            <globmapper from="myappname-*.apk" to="myappname-*.${env.BUILD_NUMBER}.apk"/>
        </copy>
</target>


As you can see I'm also naming the final apk file with the Jenkins build number environment variable.  There are a lot more other env vars that Jenkins sets that you can use.

Also note the reason I've used the globmapper is that this will work for both the debug and release build targets that are pre-defined in the standard android project ant build configs. This means you can have Hudson build configs for both debug and release.

If you want your release apk to be properly signed, you need to create a certificate and then point your ant build at it (ant.properties):

key.store=path/to/my.keystore
key.alias=mykeystore

If you don't want to type in the password for each build, you can add the following to your local.properties:

key.store.password=secretpasswd
key.alias.password=secretpasswd

And also add the passwd properties to your Jenkins config (click "Advanced" button in the "Invoke Ant" section of your build config). This way you never have to check your keystore passwords into version control.

Oh as a bonus, if you want to be able to access the build information within your apps code at runtime, you can stash this in a string value by putting something
like this in your build.xml:

<property environment="env"/>
<target name="-pre-build">
        <echo file="res/values/buildtag.xml"><![CDATA[<?xml version="1.0" encoding="utf-8"?> 
            <resources>
                <string name="build_version">ABCXYZ123</string>
            </resources>
            ]]>
        </echo>
                <replace file="res/values/buildtag.xml" token="ABCXYZ123" value="${env.BUILD_TAG}"/>
</target>

Saturday, April 7, 2012

Getting Android Emulator accelerated

On Ubuntu 10.04 or later install KVM as follows:
  1. sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
  2. install 2.3.3 Intel Atom Image via Android SDK Manager
  3. run:   emulator-x86 -avd <avd_name> -nosound -qemu -m 1024 -enable-kvm
NOTE:  the -nosound is necessary due to current bug with android emulator on Ubuntu

Tuesday, February 14, 2012

Countdown and android.os.*

So I needed a countdown timer for an Android project I'm working on and after building a simple one myself, a came across android.os.CountDownTimer - who knew android shipped with one!

That got me interested in having a browse through andriod.os.* package to see what else the Android devs had squirreled away in there...

Turns out a whole bunch of handy stuff!  Like:


Thursday, January 12, 2012

Android testing with ant

When running android tests using ant, you can specify a specific device to run the tests on when you have more than 1 device available to adb on your system. The property is: adb.device.arg so you can do:

ant -Dadb.device.arg="-s emulator-5554"

Or even better use a script like this gist.



Monday, January 9, 2012

Jenkins, adb, ant, oh my!

So this bug, who's root cause is this bug (yes reported in Jul '09 and still not fixed!), means that if you want to have a unit test failure cause your whole Ant build to fail and thus show up on your Jenkins/Hudson CI server, you need to do put this macro override into your build.xml.