- 
      
 - 
        
Save suplo/e5d61998317c15642173 to your computer and use it in GitHub Desktop.  
    Automatic versioning in Android using Ant and Git
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?xml version="1.0" encoding="UTF-8"?> | |
| <project name="application-custom"> | |
| <macrodef name="git" taskname="@{taskname}"> | |
| <attribute name="command" /> | |
| <attribute name="dir" default="" /> | |
| <attribute name="property" default="" /> | |
| <attribute name="taskname" default="" /> | |
| <attribute name="failonerror" default="on" /> | |
| <element name="args" optional="true" /> | |
| <sequential> | |
| <exec executable="git" dir="@{dir}" outputproperty="@{property}" | |
| failifexecutionfails="@{failonerror}" failonerror="@{failonerror}"> | |
| <arg value="@{command}" /> | |
| <args/> | |
| </exec> | |
| </sequential> | |
| </macrodef> | |
| <target name="-pre-build"> | |
| <git command="rev-list" property="versioning.code" taskname="versioning"> | |
| <args> | |
| <arg value="master" /> | |
| <arg value="--first-parent" /> | |
| <arg value="--count" /> | |
| </args> | |
| </git> | |
| <git command="describe" property="versioning.name" taskname="versioning"> | |
| <args> | |
| <arg value="--tags" /> | |
| <arg value="--dirty" /> | |
| <arg value="--abbrev=7" /> | |
| </args> | |
| </git> | |
| <echo level="info" taskname="versioning">${versioning.code}, ${versioning.name}</echo> | |
| <replaceregexp file="AndroidManifest.xml" match='android:versionCode=".*"' replace='android:versionCode="${versioning.code}"' /> | |
| <replaceregexp file="AndroidManifest.xml" match='android:versionName=".*"' replace='android:versionName="${versioning.name}"' /> | |
| </target> | |
| <target name="-post-build" > | |
| <replaceregexp file="AndroidManifest.xml" match='android:versionCode=".*"' replace='android:versionCode="0"' /> | |
| <replaceregexp file="AndroidManifest.xml" match='android:versionName=".*"' replace='android:versionName="0"' /> | |
| </target> | |
| </project> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment