We recently faced a problem that a customer published a version of his app that has a version code higher than 65.535 defined in the manifest file. All new builds needs greater version codes, which will fail with "Error executing task Aapt: VersionCode is outside 0, 65535 interval".

This post describes two ways to work around this Xamarin.Android limitation, when resetting the build-number is not an option.

How can this happen

As we first heard about that issue we wondered how this could happen. We took a look at the build process and couldn't find anything that is obvious. It is counting up the build number and set that as the version code.

Yet, there are cases that can lead you into this trouble. One to mention is the case if you are using the entire build date as your version code. We have seen some configurations going that way. That is not a problem in general as the max value of an integer is big enough. Google Play accepts version codes up to 2.100.000.000 according to the documentation.

How to fix that - Option 1

Searching for a solution I came to this question at the Xamarin forums and this bug ticket. Both suggest to disable the "Generate one package (.apk) per selected ABI" option under the Android Build settings.

image

This suggested solution works. But it can lead in a bloated apk file depending on the selected ABIs configured under the "Advanced"-tab. If you distribute separate ABI-packages to Google Play, you need another way to go.

How to fix that - Option 2

If you do not want to end like this guy on stackoverflow, follow these steps to update your version code after Xamarin.Android builds your apk.

  1. Build your Xamarin Android project with any version code between 0 and 65000
  2. Open a command line and call

    apktool d $APK_PATH -o $OUTPUT_FOLDER
    
  3. Open the apktool.yml text file and alter the versionCode entries

  4. Rebuild with

    apktool build $OUTPUT_FOLDER
    
  5. The new apk needs to be re-signed with the original keystore file

    jarsigner -verbose -keystore $KEYSTORE_PATH -storepass $KEYSTORE_PASSWORD -keypass $KEYSTORE_KEY_PASSWORD $APK_PATH $KEYSTORE_KEY_NAME ~/android-sdk/build-tools/25.0.2/zipalign  -v 4 $APK_PATH $APK_OUT_PATH`
    

A quick reminder to take a look at Xamarins documentation on how you should create version codes for abi specific apks, if you go that route.

comments powered by Disqus