12+ Jahre App-Entwicklung
Alles aus einer Hand
50+ Erfolgreiche App-Projekte

Blog

How to workaround Xamarin Androids VersionCode limitation

Learn why your Xamarin Android build fails with "Error executing task Aapt: VersionCode is outside 0, 65535 interval" and how to workaround that issue.

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 bug ticket 51620 - which is not accessesible anymore due to the move from bugzilla to github. 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.

Sebastian Seidel

Sebastian Seidel

Als Mobile-Enthusiast und Geschäftsführer der Cayas Software GmbH ist es mir ein großes Anliegen, mein Team und unsere Kunden zu unterstützen, neue potenziale zu entdecken und gemeinsam zu wachsen. Hier schreibe ich vor allem zur Entwicklung von Android und iOS-Apps mit Xamarin und .NET MAUI.

Verwandte Artikel

Voice input facilitates documentation - A hackathon topic
Voice input facilitates documentation - A hackathon topic

Voice input makes it possible to intuitively record food eaten and drunk without having to look at a device or tap. Instead of laboriously entering everything by hand, users can simply record their meals and snacks by voice command. This approach can lower the inhibition threshold and encourage users to continuously document their eating habits. This saves time and encourages regular documentation.

Animations in Jetpack Compose
Animations in Jetpack Compose

Modern applications are becoming more design-centric and therefore end-user-centric. For the user, the technical side of the program is not at all interesting, but rather taken for granted. Attractive design, animation and ease of use, on the contrary, all other things being equal, can make the application more popular among competitors.

7 Schritte zur Migration von Xamarin.Forms zu .NET MAUI
7 Schritte zur Migration von Xamarin.Forms zu .NET MAUI

Mit dem nahenden Ende des Supports für Xamarin im Mai 2024 sind Entwickler damit beschäftigt, bestehende Xamarin.Forms-Projekte auf .NET MAUI als Nachfolger zu migrieren. Das tun wir natürlich auch. In diesem Artikel zeige ich 7 Schritte, die wir während des Übergangs immer machen mussten, um Ihnen den Umstieg auf .NET MAUI zu erleichtern.