Update VersionName in AndroidManifest.xml
I’ve spent lot of time by finding possibility how to automatically update VersionName info inside of AndroidManifest.xml file. I found that such functionality is not placed in Eclipse or IntelliJ Idea dev tools. Therefore I started to working on my own implementation for it. Goal was to get updated VersionName anytime I’ve debug or run the android app.
After various tries I finally place my vote for Ant target. Reason was simple, the Ant build files are supported by both dev tools I mentioned earlier.
I’ve created simple Ant build file with target UpdateVersionName. File can be found at https://github.com/dczupek/UpdateManifestVersionName. The VersionName is created from majorversion and formatted date by versionformat. If you don't specify your own majorversion or versionformat the target defaults will be used. Default majorversion is "1" and default versionformat is "MM.dd.HHmm". This produce VersionName like "1.12.16.2304"
Usage:
In Eclipse:
Under project properties choose Builders and click on New
Choose "Ant Builder"
Name the builder
Into BuildFile field type (expecting that SetVersionName.xml will be in the app root):
${project_loc}\SetVersionName.xml
Within Arguments section you can override target defaults for majorversion and versionformat by setting new property value for example:
-Dmajorversion=1 -Dversionformat=MM.dd.HHmm
On the Refresh tab choose to refresh "The project containing the selected resource"
On the Targets tab choose "UpdateVersionName" target as targets for: - After a "Clean" - Manual Build - Auto Build And confirm with OK
In the list of project builders move created builder to the very top position in order to be run as very first builder
In IntelliJ Idea:
In the "Ant Build" view click on + sign
Choose the SetVersionName.xml file from the file list and confirm
On "UpdateVersionName" target choose to be executed "Before Run/Debug" by right click followed by "Execute on" option list
If you want to override target defaults for majorversion or versionformat do following:
On the SetVersionName.xml within Ant Build list do right click and choose "Properties"
In the "Properties" window choose "Properties" tab
Click "Add" as name type "majorversion" as value type for example "1" Click "Add" as name type "versionformat" as value type for example "MM.dd.HHmm"
Hope you will enjoy it. Happy versioning and coding :)