-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] Implement a new process for defining ve…
…rsionCode. Context https://bugzilla.xamarin.com/show_bug.cgi?id=51620 Context https://bugzilla.xamarin.com/show_bug.cgi?id=51618 Context https://bugzilla.xamarin.com/show_bug.cgi?id=51145 Our current version system for multiple apk's for each Abi is a bit broken [1]. If a user for example has a versionCode set which is 123 the final version code for an x86_64 build ends up as 327803. This is completely transparent to the user and also does not follow the guidance in the documentation at [1] and [2]. So we need a new system :) but as usual we have to support the old system. So we are introducing a new system which is more flexible. This will only apply when the `$(AndroidCreatePackagePerAbi)` is set to `True`. The new system has two new properties <AndroidVersionCodePattern/> <AndroidVersionCodeProperties/> The first allows the developer to define the Pattern to be used for the versonCode. The pattern will be made up of a format string which will contain keys. These keys will be replaced with values form one of the known keys or a custom user defined one. We define a few known key values - abi : The current target abi converted to an int where - 'armeabi' = 1, - 'armeabi-v7a' = 2, - 'x86' = 3, - 'arm64-v8a' = 4, - 'x86_64' = 5, - minSDK : The minSDK value from the manifest or 11 if not present. - versionCode : The versionCode from the manifest. With these keys the user can define a pattern of {abi}{minSDK}{versionCode} or if they way to include zero padding they can use {abi}{minSDK}{versionCode:D4} similar to the left padding formats used in string.Format (). Users can also use the `$(AndroidVersionCodeProperties)` property to define new custom keys. This string will be in the form of a semi-colon delimited key=value pairs. For example foo=12;bar=$(SomeBuildProperty) when can then be used in the pattern. {abi}{foo}{bar}{versionCode} Lets work through an example. The user defines a version code of '123' in the manifest and enables `$(AndroidCreatePackagePerAbi)`. They define a `$(AndroidVersionCodePattern)` of `{abi}{versionCode:D5}`. This will result in the following version code being produced for the 'x86' build. 300123 The first 3 is the `{abi}` value. The rest is the left zero padded versionCode. A slightly more complex pattern would be `{abi}{minSDK:D2}{versionCode:D4}` which would produce 3140123 if the minimumSdk value was set to API 14. A more real life example mgiht be as follows. A user wants to use the `Build` value from the AssemblyInfo.cs . They define the following target ```xml <Target Name="_GetBuild" AfterTargets="Compile"> <GetAssemblyIdentity AssemblyFiles="Foo.dll"> <Output TaskParameter="Assemblies" ItemName="MasterVersion"/> </GetAssemblyIdentity> <PropertyGroup> <BuildVersion>$([System.Version]::Parse(%(MasterVersion.Version)).Build)</BuildVersion> </PropertyGroup> </Target> ``` This extracts the build version from the built assembly. They can then define a pattern of {abi}{minSDK}{build:D4} and set the properties to build=$(BuildVersion) Given similar properties from the previous example e.g abi=x86 and minSDk=14, this will result in the follwing output (assuming the `Build` value was 3421). 3143421 [1] https://developer.xamarin.com/guides/android/advanced_topics/build-abi-specific-apks/ [2] https://developer.android.com/google/play/publishing/multiple-apks.html#Rules
- Loading branch information
1 parent
1ea5f07
commit ed90962
Showing
5 changed files
with
289 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.