Monday, October 7, 2013

Versioning Android apps with git tags, using the new Gradle-based build system

At Onavo we version our Android and iOS apps with git tags (inspired by Fraser Hess). No more mucking about with manifests and plists in short-lived branches.
  • Our release git tags look like abc1.2.3-foo_15_bar, which translates to a version name of 1.2.3-foo and a version code of 15.
    • The 'abc' prefix differentiates between different apps on the same repo, and is ignored.
    • The 'bar' suffix differentiates between identical version names and version codes, and is also ignored. We sometimes need this when a a bad tag was made and pushed and we have to retag with the proper revision, since replacing a pushed tag in git isn't wise.
  • Our apk filenames look like appname-flavor-release-1.2.3-rc2-68fb97b.apk
Android's Gradle-based build system makes this super sweet. Here's how we do it:

To see something different, +Jake Wharton describes an awesome approach to versioning & git hacks with Gradle.
Soon I'll hopefully write about how we use Gradle with different flavors, and some some apk signing hacks.

EDIT: I forgot to explain the mysterious tagToBuildFrom - it's for the cases when we release a version of 2 different apps from the same git revision. There are 2 git tags, and "git describe --exact HEAD" will arbitrarily choose one. We can force gradle to use a specific tag by running:
./gradlew --daemon assembleRelease -PtagToBuildFrom=myapp4.5.6_31