ewtroan (ewtroan) wrote,

Buiding multiple versions of an android app

I've been playing with Android development a bit, and I had an app I wanted to build two slightly different versions of. I found a few methods for doing this, none of which I really liked. After some hotel room fiddling, I found a relatively clean way of adding an ant task which would build a second version of my app. I'm using a different manifest and activity (which is derived from the normal activity class) for my second version rather than any resource changes. It's small and I don't care much about a few wasted bits here. It would be quite easy to change the method to build an entirely different resource set into the second version if that's more interesting.

A couple of things to note -- this block goes after the in build.xml. One of the reasons I like my approach better than some of the others I've found is it doesn't involve copying build logic from the android platform ant tasks into this build.xml. The whole thing adds a demo target, so running "ant demo" will build the second version of the app. It will recompile the java as needed. This isn't tied into ant clean unfortunately, so detritus will be left standing. Finally, you need to place the apps in different packages to be simultaneously installable. Make sure the second manifest (demo/AndroidManifest.xml here) is correct for the new version. Improvements and suggestions are welcome! This is the first time I've ever touched ant, and as such I gave up before doing things like using the apkbuilder task.

    <target name="demo" depends="-dex">
        <echo>Packaging demo resources</echo>

        <aaptexec executable="${aapt}"
            <res path="${resource.absolute.dir}" />

        <echo>Building bin/SampleAppDemo-unaligned-debug.apk</echo>
        <exec executable="${sdk.dir}/tools/apkbuilder">
            <arg value="${out.dir}/SampleAppDemo-unaligned-debug.apk"/>
            <arg value="-u"/>
            <arg value="-z"/>
            <arg value="${out.dir}/SampleAppDemo.ap_"/>
            <arg value="-f"/>
            <arg value="${out.dir}/classes.dex"/>
        <echo>Signing demo with debug key</echo>
        <exec executable="jarsigner">
            <arg value="-storepass"/>
            <arg value="android"/>
            <arg value="-keystore"/>
            <arg value="../../.android/debug.keystore"/>
            <arg value="${out.dir}/SampleAppDemo-unaligned-debug.apk"/>
            <arg value="androiddebugkey"/>
        <echo>Aligning demo package</echo>
        <exec executable="${zipalign}">
            <arg value="-f"/>
            <arg value="4"/>
            <arg value="${out.dir}/SampleAppDemo-unaligned-debug.apk"/>
            <arg value="${out.dir}/SampleAppDemo-debug.apk"/>

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened