Thursday, July 21, 2011

Updating versionCode and versionNumber in Android manifest via Gradle

I'm working on Android project which has multiple builds for different customers.
Each build is organized as separate project and is build via Ant script. The problem is that building all those builds and updating versionCode and versionNumber is all manifest files takes a lot of time. So, I decided to use some tool to this for me. Yes, I'm a bit lazy :)
I've chosen Gradle. It leverages the power of Groovy and is able to call Ant scripts.
Groovy has great tools to work with XML, like XmlSlurper. So, updating versionCode and versionNumber in Android manifest files seemed easy. Unfortunately after significant amount of time all I got was ugly formatted Android manifest with tag0 namespaces :(
Then I put XmlSlurper aside and used String.replaceAll(Pattern pattern, String replacement) method. It took me about 5 minutes to do all replacements :)

2 comments:

Anonymous said...

I really liked the article, and the very cool blog

fatmi said...

Great article helped me very much.

Jaycon