I believe that computers are the best things for doing repetitive tasks. I certainly am not, I either forget, or (mostly) don\'t do things in a consistent way - which isn\'
ok, here's a novel way of doing it:
for calculating version.code
:
git rev-list master --first-parent --count
this follows the versioning guideline. As it effectively finds the number of commits from the initial commit (inclusive) which is always incrementing from the previous version.
for calculating the version.name
:
git describe --tags --dirty --abbrev=7
build.xml
usually imports a custom ant script called custom_rules.xml
so making the content of the script as:
${versioning.code}, ${versioning.name}
would just do.
In a nut shell, it just replaces the android.versionCode
and android.versionName
with the current version code and name, stored in git.
-post-build
target, or (though I highly doubt you would require it) you could make it configurable and place it in some property (file or embedded; your choice)Enjoy.
HEAD
to calculate the build number; causes version downgrade issue when doing a build during development, and later when installing the stable version (or when doing a beta to main release transition). using the master
(or the branch which is used for production builds) ref instead.PS: relevant for AS users: Automatically versioning Android project from git describe with Android Studio/Gradle