Skip to content

Commit 31b2078

Browse files
authored
[build] Build with Android SDK Platform-tools r31.0.3 (#6424)
Context: dotnet/java-interop@79744f6 Context: f6011d9 Commit f6011d9 updated external/xamarin-android-tools so that the Android SDK platform-tools r31.0.3 package would be preferred, but *didn't* update `$(XAPlatformToolsVersion)` to cause the xamarin-android build to use platform-tools r31.0.3, because: > The reason to *not* bump `$(XAPlatformToolsVersion)` is that > attempting to do so breaks the `src/Mono.Android` build: > > 1. platform-tools r31.0.3 doesn't contain > `platform-tools/api/annotations.zip`, which is used by > `generator` to emit certain custom attributes such as > `RequiresPermission`. > > 2. While (1) can be worked around by instead using > `$(AndroidSdkDirectory)/platforms/android-*/data/annotations.zip`, > this introduces API changes reported by the > `_CheckApiCompatibility` target, in particular changes due to > custom attribute string changes. These string changes happen > because Google ships *invalid XML* in `data/annotations.zip` for > API-29+ (?!): dotnet/java-interop@79744f61 is the fix for (2), and should allow us to use platform-tools r31.0.3 for the xamarin-android build. Commit 43243b4 bumped to dotnet/java-interop@79744f61, which includes dotnet/java-interop@79744f61. We can now build xamarin-android with Android SDK Platform-tools r31.0.3. One of the (undocumented) changes between Android SDK Platform-tools package r30.0.4 and r31.0.3 is that `platform-tools/api/annotations.zip` was *removed*. This removal would cause the `_GenerateBinding` target in `Mono.Android.targets` to fail, as it's used by `generator.exe --annotations`: mono --debug=casts "/Users/builder/azdo/_work/2/s/xamarin-android/bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/generator.exe" \ --annotations="/Users/builder/Library/Android/sdk/platform-tools/api/annotations.zip" \ … … error BG0000: System.IO.DirectoryNotFoundException: Could not find a part of the path "/Users/builder/Library/Android/sdk/platform-tools/api/annotations.zip". at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) at System.IO.File.OpenRead (System.String path) at Xamarin.AndroidTools.AnnotationSupport.AndroidAnnotationsSupport.ParseArchive (System.String file) at Xamarin.AndroidTools.AnnotationSupport.AndroidAnnotationsSupport.Load (System.String annotationsZipFile) at Xamarin.Android.Binder.CodeGenerator.GenerateAnnotationAttributes (System.Collections.Generic.List`1[T] gens, System.Collections.Generic.IEnumerable`1[T] zips) at Xamarin.Android.Binder.CodeGenerator.Run (Xamarin.Android.Binder.CodeGeneratorOptions options, Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver) at Xamarin.Android.Binder.CodeGenerator.Run (Xamarin.Android.Binder.CodeGeneratorOptions options) at Xamarin.Android.Binder.CodeGenerator.Main (System.String[] args) `annotations.zip` has moved into the platform package, and has been there since API-26: % ls -1tr ~/android-toolchain/sdk/platforms/*/data/annotations.zip $HOME/android-toolchain/sdk/platforms/android-26/data/annotations.zip $HOME/android-toolchain/sdk/platforms/android-27/data/annotations.zip $HOME/android-toolchain/sdk/platforms/android-28/data/annotations.zip $HOME/android-toolchain/sdk/platforms/android-29/data/annotations.zip $HOME/android-toolchain/sdk/platforms/android-30/data/annotations.zip $HOME/android-toolchain/sdk/platforms/android-31/data/annotations.zip Update the `_GenerateBinding` target so that the "new" platform copy of `annotations.zip` is used, if present. Update `Android.Runtime.IntDefAttribute` and `Android.RUntime.StringDefAttribute` so that they can be applied to fields. This fixes errors such as: …/src/Mono.Android/obj/Debug/net6.0/android-31/mcw/Android.Service.Autofill.FillRequest.cs(27,4): error CS0592: Attribute 'global::Android.Runtime.IntDef' is not valid on this declaration type. It is only valid on 'constructor, method, property, indexer, parameter' declarations. …/src/Mono.Android/obj/Debug/net6.0/android-31/mcw/Android.Service.Autofill.FillRequest.cs(32,4): error CS0592: Attribute 'global::Android.Runtime.IntDef' is not valid on this declaration type. It is only valid on 'constructor, method, property, indexer, parameter' declarations. …/src/Mono.Android/obj/Debug/net6.0/android-31/mcw/Android.Views.InputMethods.InlineSuggestionInfo.cs(27,4): error CS0592: Attribute 'global::Android.Runtime.StringDef' is not valid on this declaration type. It is only valid on 'constructor, method, property, indexer, parameter' declarations. …/src/Mono.Android/obj/Debug/net6.0/android-31/mcw/Android.Views.InputMethods.InlineSuggestionInfo.cs(32,4): error CS0592: Attribute 'global::Android.Runtime.StringDef' is not valid on this declaration type. It is only valid on 'constructor, method, property, indexer, parameter' declarations. for generated code such as: partial class FillRequest { [Register ("FLAG_COMPATIBILITY_MODE_REQUEST", ApiSince = 29)] [global::Android.Runtime.IntDef (Flag = true, Type = "Android.Service.Autofill.FillRequest", Fields = new string [] {"FlagManualRequest", "FlagCompatibilityModeRequest"})] public const int FlagCompatibilityModeRequest = (int) 2; } partial class InlineSuggestionInfo { [Register ("SOURCE_AUTOFILL", ApiSince = 30)] [global::Android.Runtime.StringDef (Type = "Android.Views.InputMethods.InlineSuggestionInfo", Fields = new string [] {"SourceAutofill", "SourcePlatform"})] public const string SourceAutofill = (string) "android:autofill"; } Update `tests/api-compatibility/acceptable-breakages-*.txt` to deal with the API breakage caused by using `platforms/android-*/data/annotations.zip` instead of `platform-tools/api/annotations.zip`. This will result in numerous changes to custom attributes, but these are *correct* changes, properly mirroring the changes in the Android SDK.
1 parent 29740ab commit 31b2078

10 files changed

+156
-12
lines changed

Configuration.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@
124124
<XABuildToolsPackagePrefix Condition=" '$(HostOS)' == 'Windows' ">$(XABuildToolsPackagePrefixWindows)</XABuildToolsPackagePrefix>
125125
<XABuildToolsVersion>30.0.3</XABuildToolsVersion>
126126
<XABuildToolsFolder Condition="'$(XABuildToolsFolder)' == ''">30.0.3</XABuildToolsFolder>
127-
<XAPlatformToolsPackagePrefix Condition=" '$(HostOS)' == 'Darwin' ">b2be9c80582174e645d3736daa0d44d8610b38a8.</XAPlatformToolsPackagePrefix>
128-
<XAPlatformToolsVersion>30.0.2</XAPlatformToolsVersion>
127+
<XAPlatformToolsPackagePrefix Condition=" '$(HostOS)' == 'Darwin' ">e8b2b4cbe47c728c1e54c5f524440b52d4e1a33c.</XAPlatformToolsPackagePrefix>
128+
<XAPlatformToolsVersion>31.0.3</XAPlatformToolsVersion>
129129
<XAIncludeProprietaryBits Condition="'$(XAIncludeProprietaryBits)' == ''">False</XAIncludeProprietaryBits>
130130
<XABundleToolVersion Condition="'$(XABundleToolVersion)' == ''">1.8.1</XABundleToolVersion>
131131
<XAPackagesDir Condition=" '$(XAPackagesDir)' == '' And '$(HostOS)' == 'Windows'">$(userprofile)\.nuget\packages</XAPackagesDir>

src/Mono.Android/Android.Runtime/IntDefAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Android.Runtime
44
{
55
// Field can be target too, but our toolchain doesn't generate any.
6-
[AttributeUsage (AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = true)]
6+
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = true)]
77
public class IntDefAttribute : Attribute
88
{
99
public bool Flag { get; set; }

src/Mono.Android/Android.Runtime/StringDefAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Android.Runtime
44
{
55
// Field can be target too, but our toolchain doesn't generate any.
6-
[AttributeUsage (AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = true)]
6+
[AttributeUsage (AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = true)]
77
public class StringDefAttribute : Attribute
88
{
99
public string? Type { get; set; }

src/Mono.Android/Mono.Android.targets

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,15 @@
135135
</Target>
136136
<Target Name="_GenerateBinding"
137137
BeforeTargets="CoreCompile"
138-
Inputs="metadata;enumflags;map.csv;methodmap.csv;$(IntermediateOutputPath)mcw\api.xml"
138+
Inputs="$(MSBuildThisFileFullPath);metadata;enumflags;map.csv;methodmap.csv;$(IntermediateOutputPath)mcw\api.xml"
139139
Outputs="$(IntermediateOutputPath)mcw\Mono.Android.projitems">
140140
<MakeDir Directories="$(IntermediateOutputPath)mcw" />
141141
<PropertyGroup>
142142
<_PlatformIdVersions>$(AndroidSdkDirectory)\platforms\android-$(AndroidPlatformId)\data\api-versions.xml</_PlatformIdVersions>
143+
<_AndroidPlatformAnnotations>$(AndroidSdkDirectory)/platforms/android-$(AndroidPlatformId)/data/annotations.zip</_AndroidPlatformAnnotations>
144+
<_PlatformToolsAnnotations>$(AndroidSdkDirectory)/platform-tools/api/annotations.zip</_PlatformToolsAnnotations>
145+
<_AnnotationsZip Condition=" Exists($(_AndroidPlatformAnnotations)) ">$(_AndroidPlatformAnnotations)</_AnnotationsZip>
146+
<_AnnotationsZip Condition=" '$(_AnnotationsZip)' == '' And Exists('$(_PlatformToolsAnnotations)') ">$(_PlatformToolsAnnotations)</_AnnotationsZip>
143147
</PropertyGroup>
144148
<ItemGroup>
145149
<_ApiVersion
@@ -160,7 +164,7 @@
160164
<_Fixup>--fixup=metadata</_Fixup>
161165
<_Enums1>--preserve-enums --enumflags=enumflags --enumfields=map.csv --enummethods=methodmap.csv</_Enums1>
162166
<_Enums2>--enummetadata=$(IntermediateOutputPath)mcw\enummetadata</_Enums2>
163-
<_Annotations>--annotations="$(AndroidSdkDirectory)/platform-tools/api/annotations.zip"</_Annotations>
167+
<_Annotations Condition=" '$(_AnnotationsZip)' != '' ">"--annotations=$(_AnnotationsZip)"</_Annotations>
164168
<_Assembly>--assembly="Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"</_Assembly>
165169
<_TypeMap>--type-map-report=$(IntermediateOutputPath)mcw\type-mapping.txt</_TypeMap>
166170
<_Api>$(IntermediateOutputPath)mcw\api.xml</_Api>

tests/api-compatibility/acceptable-breakages-v10.0.txt

Lines changed: 81 additions & 2 deletions
Large diffs are not rendered by default.

tests/api-compatibility/acceptable-breakages-v11.0.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
Compat issues with assembly Mono.Android:
2+
CannotRemoveAttribute : Attribute 'Android.Runtime.RequiresPermissionAttribute' exists on 'Android.Net.Wifi.WifiManager.RemovePasspointConfiguration(System.String)' in the contract but not the implementation.
3+
CannotRemoveAttribute : Attribute 'Android.Runtime.RequiresPermissionAttribute' exists on 'Android.Telecom.TelecomManager.GetLine1Number(Android.Telecom.PhoneAccountHandle)' in the contract but not the implementation.
4+
CannotChangeAttribute : Attribute 'Android.Runtime.RequiresPermissionAttribute' on 'Android.Telephony.TelephonyManager.Nai.get()' changed from '[RequiresPermissionAttribute("android.permission.READ_PHONE_STATE")]' in the contract to '[RequiresPermissionAttribute("android.permission.READ_PRIVILEGED_PHONE_STATE")]' in the implementation.
25
TypesMustExist : Type 'Android.Bluetooth.BluetoothProfileConsts' does not exist in the implementation but it does exist in the contract.
36
TypesMustExist : Type 'Android.Content.ComponentCallbacks2Consts' does not exist in the implementation but it does exist in the contract.
47
TypesMustExist : Type 'Android.Content.DialogInterfaceConsts' does not exist in the implementation but it does exist in the contract.

0 commit comments

Comments
 (0)