Repository navigation
Decorate all APIs with correct SupportedOSPlatform attributes #5338
Description
Activity
- addedArea: Mono.AndroidIssues with the Android API binding (Mono.Android.dll).Issues with the Android API binding (Mono.Android.dll).
on Nov 27, 2020 After reading the Platform compatibility analyzer doc page I saw attributes like
[SupportedOSPlatform("Android6.0")]. I'm curious if the effort for this issue is going to include the android only API? For example://This is the C# class that is a binding of android.view.View //(https://developer.android.com/reference/android/view/View.html) public class View { [SupportedOSPlatform("Android8.0")] // This means that this property can only be used on Android 8.0 or above //which corresponds to API 26 or above since this is the version it was added in //(https://developer.android.com/reference/android/view/View.html#getTooltipText()) public string TooltipText { get; set; } }
Or is only the net5.0 API going to be annotated?
This issue is for Android APIs only
I think the attributes will actually be the API level such as:
[SupportedOSPlatform("android30")]
See: dotnet/runtime#43531
We'll have to see if we have to see if we have to put
android30.0, I but I think we should try leaving off the.0.major.minoris requiredSo I think we will have to use
android30.0, etc.Additionally,
SupportedOSPlatformis only available in .NET 5+; thus,generatoroutput will need to wrap it into a#if NET5block:// Metadata.xml XPath class reference: path="/api/package[@name='android.app']/class[@name='Activity']" [global::Android.Runtime.Register ("android/app/Activity", DoNotGenerateAcw=true)] #if NET5_0_OR_GREATER [global: System.Runtime.Versioning.SupportedOSPlatform ("android")] #endif // NET5_0_OR_GREATER public partial class Activity { public virtual unsafe bool IsActivityTransitionRunning { // Metadata.xml XPath method reference: path="/api/package[@name='android.app']/class[@name='Activity']/method[@name='isActivityTransitionRunning' and count(parameter)=0]" [Register ("isActivityTransitionRunning", "()Z", "GetIsActivityTransitionRunningHandler", ApiSince = 26)] #if NET5_0_OR_GREATER [global::System.Runtime.Versioning.SupportedOSPlatform ("android26.0")] #endif // NET5_0_OR_GREATER get {…} } }
I think it's probably easier to define our own
[SupportedOSPlatform]attribute and include it if not targeting net5.0+.I think it's probably easier to define our own [SupportedOSPlatform] attribute and include it if not targeting net5.0+.
You could public [Conditional("NEVER")] on the local version of SupportedOSPlatformAttribute to be always removed by compiler for non-netcore builds
Implementation details aside, the good news is we do already have this data and already put it in our bindings, just in a different place (
ApiSince), so it won't be hard to add the new annotations.[global::Android.Runtime.Register ("android/accessibilityservice/FingerprintGestureController$FingerprintGestureCallback", DoNotGenerateAcw=true, ApiSince = 26)] public abstract partial class FingerprintGestureCallback : Java.Lang.Object { [Register (".ctor", "()V", "", ApiSince = 26)] public unsafe FingerprintGestureCallback () : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) { ... } }We will probably need to manually audit our hand-bound code also.
- added a commit that references this issue
on Jan 11, 2021 - added a commit that references this issue
on May 17, 2021 This has been implemented in Java.Interop:
dotnet/java-interop@412e974And bumped in XA:
#5945- ghost locked as resolved and limited conversation to collaborators
on Jun 3, 2022
As part of netcore migration, we need to correctly annotate all APIs with .NET 6 to work correctly with existing tooling (primary existing analyzers). The attributes already exist in .NET5 and could be extended if necessary.
Available attributes are listed at https://github.com/dotnet/designs/blob/main/accepted/2020/platform-checks/platform-checks.md#attributes