This solution was developed on Linux. I'm sure experienced Windows and Mac developers can adapt them to their platforms, but I'm not such a developer. Linux is where my skill set lives.
Git has a nice feature in the git describe --dirty . It bounces back the commit log and finds the tag, and then builds the version string. If this is a “production build" where the last commit was flagged and all files were checked, then this is your version string. If this is a development assembly, then the last tag is added with the number of additional commits and a shortened hash code. The --dirty flag is just a cherry on the icing on the cake: it adds the word dirty if there are any modified files that have not yet been committed. This is perfect for your android:versionName in the manifest file.
android:versionCode requires a number. This is needed for watches for releases, but not for building development, and since each version will have a tag with the version, I just count them. I always mark my versions in the form v<major>.<minor>[.<patch>] , where <major> , <minor> and <patch> are just numbers. Therefore, tags that start with the lowercase “v” are counted, followed by a digit, all of which is really necessary here.
After completing the template manifest file, I found that the best way is to simply use the AndroidManifest.xml file in the project database, edited using the sed stream editor, and put the result in bin / AndroidManifest.xml.
So, I developed the script below, placing it in the scripts folder at the same level as my projects (so that they all can share the same script), and then set up my own constructor in Eclipse.
There is a script that I called version.sh :
#/bin/bash echo "Auto Version: `pwd`" CODE=`git tag | grep -c ^v[0-9]` NAME=`git describe --dirty | sed -e 's/^v//'` COMMITS=`echo ${NAME} | sed -e 's/[0-9\.]*//'` if [ "x${COMMITS}x" = "xx" ] ; then VERSION="${NAME}" else BRANCH=" (`git branch | grep "^\*" | sed -e 's/^..//'`)" VERSION="${NAME}${BRANCH}" fi echo " Code: ${CODE}" echo " Ver: ${VERSION}" cat AndroidManifest.xml | \ sed -e "s/android:versionCode=\"[0-9][0-9]*\"/android:versionCode=\"${CODE}\"/" \ -e "s/android:versionName=\".*\"/android:versionName=\"${VERSION}\"/" \ > bin/AndroidManifest.xml exit 0
To configure the constructor, follow these steps:
one). Right-click the project base and select Properties and then Builders.
2). Click the "Create" button and select "Program."
3). Name your version something like "<project> Auto Version". This line should be unique for all projects.
four). Set up the Home tab as follows:
4a). In the Location section, use File System Overview and navigate and select the script file.
4b). In the "Working Directory" section, use "Workspace Overview" to select a project.
5). Leave the "Update resources after completion" checkbox unchecked on the "Update" tab.
6). Do not set any variables on the Environment tab.
7). On the Build Options tab:
7a). Make sure "During manual builds" is checked and
7b). Also marked "During Auto Build".
7c). Now I have the rest. I don’t even give him a console. The eagle watching him may have noticed that the script is displaying some information, but now it works for me, I just want everything to be quiet, without bothering me.
8). Fine tune your build options, and then place your constructor between Android Precompilation and Java Builder.
Go back to creating secure applications, knowing that they are correctly versioned, and check the information about your application. Isn't that a version number .:-)
Steve