Skip to content

[build] Build with Android SDK Platform-tools r31.0.3 #6424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2021

Conversation

jonpryor
Copy link
Contributor

@jonpryor jonpryor commented Oct 25, 2021

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.

@jpobst jpobst force-pushed the jonp-platform-tools-r31 branch 3 times, most recently from df9b68b to 31a3f45 Compare October 26, 2021 23:26
@jonpryor jonpryor force-pushed the jonp-platform-tools-r31 branch from 31a3f45 to 3a9f14c Compare October 27, 2021 21:17
@jpobst jpobst force-pushed the jonp-platform-tools-r31 branch from 3a9f14c to c527a5b Compare October 28, 2021 14:35
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.
@jonpryor jonpryor force-pushed the jonp-platform-tools-r31 branch from c527a5b to 15cab6a Compare October 29, 2021 00:19
@jonpryor
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonpryor jonpryor marked this pull request as ready for review October 29, 2021 15:18
@jonpryor jonpryor changed the title Try xamarin/java.interop#897; Use platform-tools r31 [build] Build with Android SDK Platform-tools r31.0.3 Oct 29, 2021
Copy link
Contributor

@jpobst jpobst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the "breaking changes" look like positive changes:

  • Adding new attributes to newer API levels
  • Updating permissions to more granular permissions added in later API levels

@jonpryor jonpryor merged commit 31b2078 into dotnet:main Oct 29, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants