Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

embed version details in android APK

My code is stored in SVN version control. I use Eclipse to build my Android application.

In my application, I have an about-box. I want to show the correct source control revision/tag/whatever in this.

Is there a way of automating this so that my version string in the about-box is always right, or is this something I have to hand-edit each time I commit?

Thx for the early answers about $keywords$.

Setting the SVN property svn:keywords to Rev does expand a private String m_svn_rev = "$Rev:$" every time I submit that file.

SVN is a per-file version control system.

Which leads instead to wonder if I can somehow pre-process some files in the Android build thingy to inject svnversion output?

like image 896
Will Avatar asked Jan 29 '10 13:01

Will


2 Answers

One possible approach. In your AndroidManifest.xml add metadata to your Activities to keep the revision or whatever you want to use

<activity android:name="SampleActivity">
    <meta-data android:value="$Rev: 164 $" android:name="com.example.version" />
</activity>

then in your Activity

try {
    final ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
    final String version = (String)ai.metaData.get("com.example.version");
    System.out.println("version: " + version);
} catch (NameNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

You may also want to set android:versionName="$Rev$" in your manifest.

To automate the process of incrementing the version number in android:versionCode and committing the AndroidManifest.xml there are various options, building with maven or ant could be alternatives but let's do it using Eclipse and ADT.

First, add a builder to your project (My Project -> Properties -> Builders)

alt text

this builder should invoke the android-increment-manifest-version using the project's AndroidManifest.xml as the argument

alt text

android-increment-manifest-version script is something like

#! /bin/bash
# android-increment-manifest-version:
# increment the version number found in the AndroidManifest.xml file
# (android:versionCode="n") in place and commit it to subversion.
#
# Copyright (C) 2010 Diego Torres Milano - http://dtmilano.blogspot.com

usage() {
    echo "usage: $PROGNAME AndroidManifest.xml" >&2
    exit 1
}

PROGNAME=$(basename $0)

if [ "$#" -ne 1 ]
then
    usage
fi

MANIFEST="$1"

perl -npi -e 's/^(.*android:versionCode=")(\d+)(".*)$/"$1" . ($2+1) . "$3"/e;' $MANIFEST
svn ci -m "Version incremented" $MANIFEST
like image 99
Diego Torres Milano Avatar answered Oct 18 '22 12:10

Diego Torres Milano


generic advice only, you don't mention your version control system.

embed the appropriate header (something like $Version:$) in the text for the about box. When you commit, the new version # will be stored and when you build the value will be shown.

[edit]
1. create your about box as a separate source, only check it in when you increment the version.
2. embedded your own version in a header file (and don't forget to change it) then use that version string in your about box (as an extern string * for example)
[/edit]

like image 33
KevinDTimm Avatar answered Oct 18 '22 12:10

KevinDTimm