Bug 51620 - Build error when using a versionCode > 65535 with "Generate one package per selected ABI" feature enabled
Summary: Build error when using a versionCode > 65535 with "Generate one package per s...
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild (show other bugs)
Version: 7.0 (C8)
Hardware: Macintosh Mac OS
: High normal
Target Milestone: 15.4
Assignee: dean.ellis
: 51145 51618 (view as bug list)
Depends on:
Reported: 2017-01-18 18:27 UTC by Keith Rome
Modified: 2017-08-01 12:16 UTC (History)
4 users (show)

See Also:
Tags: bb
Is this bug a regression?: ---
Last known good build:

Sample Xamarin.Android project with android:versionCode set to 65536. (48.53 KB, application/zip)
2017-06-23 22:06 UTC, Tom Opgenorth

Description Keith Rome 2017-01-18 18:27:47 UTC
When the "Generate one package per selected ABI" feature is enabled, high numerical values for versionCode ("Version number" in the build options page) cause the build process to fail.

The error produced during build is:

> "Error executing task Aapt: VersionCode is outside 0, 65535 interval" in Xamarin.Android.Common.targets

Disabling the APK per ABI feature works around the problem, but obviously you end up with a single bloated APK that way.

NOTE: There is guidance for using scripts to control the multi-APK build process (here: https://developer.xamarin.com/guides/android/advanced_topics/build-abi-specific-apks/#Creating_the_Version_Code_for_the_APK), but the options UI does not hint at this being a requirement or suggested approach, and the article does not provide a full solution - it leaves the actual script writing/debugging up to the reader.
Comment 1 Tom Opgenorth 2017-06-23 22:06:57 UTC
Created attachment 23094 [details]
Sample Xamarin.Android project with android:versionCode set to 65536.
Comment 2 Tom Opgenorth 2017-06-23 22:16:07 UTC
Steps to duplicate:

1. Open the attached solution.
2. Check the Projection options of the Xamarin.Android project - note that the android:versionCode is set to 65536 and that the APK per ABI is checked. Also note that multiple ABIs are selected.
3. Try to build the Application, the build will fail with the specified error.
4. Go back to the Project Options for the Xamarin.Android project, under Build > Android Build > General, unselect the "On ABI per APK". 
5. Try and build the Application, the build will fail with the same error. 

Expected Result:

Multiple APIs would be created with the specified version code.
Comment 3 dean.ellis 2017-06-26 09:32:03 UTC
Looking at the docs 65535 is no longer the max value for the version code. 
It is 2100000000 so our code needs to be updated to allow this. 

[2] https://developer.android.com/studio/publish/versioning.html
Comment 4 Cody Beyer (MSFT) 2017-07-12 22:42:18 UTC
*** Bug 51145 has been marked as a duplicate of this bug. ***
Comment 5 Cody Beyer (MSFT) 2017-07-12 22:43:23 UTC
*** Bug 51618 has been marked as a duplicate of this bug. ***
Comment 6 Jonathan Pryor 2017-07-14 20:17:29 UTC
Possibly related: https://github.com/xamarin/xamarin-android/pull/692
Comment 7 dean.ellis 2017-08-01 12:16:28 UTC
We have implemented a new system for allowing the user to define a version Code format. Details of which can be found at [1].

The old system is still in place (and will remain so) because people might well be using it. That said people should migrate over to using the new system once it is released. 

The new system introduces a two new properties.


which the user can define in the .csproj. 

AndroidVersionCodePattern - is a string which contains format characters which define the versionCode pattern. For example `{abi}{versionCode:D4}`.
This will produce a version in which the first character is the abi mapped to an integer (see [2]) and the last part is a left zero padded value of the versionCode from the AndroidManifest.xml . 
So if we are targeting x86 and our versionCode in the manifest is 22 we get


as the versionCode in the final APK.

AndroidVersionCodeProperties - allows you do define you own values to use in the AndroidVersionCodePattern. e.g screen=13;someprop=$(Foo). Note you can use MSbuild properties. You can then have a AndroidVersionCodePattern of `{abi}{screen}{someprop}`.

This opens some interesting possibilities with pulling the version code from the assemblyInfo and using that. See the commit comment in [1] for more details. Or even better the docs [3] :) 

For our testers - as stated our old system must remain in place as people will be using it. So technically we have not fixed this issue, but there is a new system to help developers work with the version Code. Hence I am not marking this a FIXED but as ANSWERED.

[1] https://github.com/xamarin/xamarin-android/commit/0a2f008c8ac6e031df87209b76d4206bf63508eb
[2] https://developer.xamarin.com/guides/android/advanced_topics/build-abi-specific-apks/
[3] https://github.com/xamarin/xamarin-android/blob/master/Documentation/build_process.md#AndroidVersionCodePattern

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Note You need to log in before you can comment on or make changes to this bug.