I have application which uploaded into Subversion/SVN repo. Is it possible to use script to somehow change application version code stored in AndroidManifest
? I mea
You could do it at build time using the xpath Ant target provided by the default Android build scripts to get the current value, then use Ant replace.
SVN has keyword substitution which you can use to put the revision number in a file. However, this will result in the revision when the manifest file itself was last changed, which is not what you want.
The best way to achieve what you want is to call svnversion
from your build script, and embed the output in the manifest file from there. You could have a manifest.template
file under version control which can be used by your build script to generate the real manifest file. Put a placeholder word in the template and replace it by the revision number obtained with svnversion
.
edit: in Eclipse you would probably use an Ant script, and invoke it before the normal build. The linked example generates a class file with the revision number, but you could also generate a manifest file in a very similar way.
SVN approach is fine, but not necessarily suitable for everyone. I do prefer to have control on app versionName and versionCode increment so I did my own Java simple app to do that
Features:
Available here: android manifest build number
I've done this by adding an extra build target - so the version code is incremented when you build the project, not when you commit to SVN. These are instructions to get this to work in IntelliJ IDEA.
First, add a new file in the root of your project called svn-revision.build.xml
with the following contents:
<project default="svn-revision">
<target name="svn-revision">
<exec executable="sh" outputproperty="revision">
<arg value="-c" />
<arg value="svnversion | sed -e 's/^[^:]*://;s/[A-Za-z]//'" />
</exec>
<echo>Revision (app): ${revision}</echo>
<replaceregexp file="AndroidManifest.xml" match='android:versionCode="([^".]+)(\.[^"]*)?"' replace='android:versionCode="${revision}"' />
</target>
</project>
Then in the menu go to View > Tools > Ant Build
, then press the little +
button in the window and add the newly created file. Clicking the green 'run' button in the Ant Build window will run the script right away. To make the script run every time you build, you will need to set the 'svn-revision' target as a default target.