Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Android android:versionCode android:versionName - From Jenkins Build Server

We have a unique situation where we are deploying a Xamarin.Android app to China to 33 app stores. Hence, our solution has 33 application projects, and we setup Jenkins (running on Windows) to package and sign all our apks (otherwise it would be crazy to make builds).

We also need to modify android:versionCode and android:versionName in the manifest file, by using the ${SVN_REVISION} value from Jenkins. Is there a way to pass these values command line to MSBuild?

Normally we would hand edit this value, but it's not possible because of so many application projects.

Our build parameters right now look like this in Jenkins:

/p:Configuration=Release;AndroidKeyStore=True;AndroidSigningKeyStore=ourkeystore.keystore;AndroidSigningStorePass=ourpassword;AndroidSigningKeyAlias=ouralias;AndroidSigningKeyPass=ourpassword /t:SignAndroidPackage 
like image 225
jonathanpeppers Avatar asked Dec 25 '22 15:12

jonathanpeppers


1 Answers

Add this to the end of your *.csproj file, before the ending </Project> tag:

  <Target Name="BeforeBuild" Condition=" '$(JENKINS)' == '1' ">
    <XmlPoke XmlInputPath="Properties\AndroidManifest.xml" Namespaces="&lt;Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' /&gt;" Query="manifest/@android:versionCode" Value="$(SVN_REVISION)" />
    <XmlPoke XmlInputPath="Properties\AndroidManifest.xml" Namespaces="&lt;Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' /&gt;" Query="manifest/@android:versionName" Value="2.0.$(SVN_REVISION)" />
  </Target>

I have Jenkins configured to pass JENKINS=1 and SVN_REVISION. When it goes to build, it modifies AndroidManifest.xml before the build.

I don't know if this will work on xbuild on a Mac or not, depends on if XmlPoke is implemented. I should do a blog post on this.

like image 116
jonathanpeppers Avatar answered Jan 01 '23 16:01

jonathanpeppers