-
Notifications
You must be signed in to change notification settings - Fork 530
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
Decorate all APIs with correct SupportedOSPlatform attributes #5338
Comments
After reading the Platform compatibility analyzer doc page I saw attributes like //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 |
So I think we will have to use |
Additionally, // 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 |
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 (
We will probably need to manually audit our hand-bound code also. |
) Context: dotnet/android#5338 .NET 5 provides a new [`System.Runtime.Versioning.SupportedOSPlatformAttribute`][0] custom attribute which is used to specify on which platforms and platform versions an API is available. This is used to build analyzers to give users warnings if they are trying to use an API when it will not be available on their target platform. `SupportedOSPlatformAttribute` is fundamentally the same as our existing `RegisterAttribute.ApiSince` property, except tooling has actually been built to consume the information. As such, we need `generator` support to put this information into `Mono.Android.dll`: partial class Activity { // Metadata.xml XPath method reference: path="/api/package[@name='android.app']/class[@name='Activity']/method[@name='dismissKeyboardShortcutsHelper' and count(parameter)=0]" [global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android24.0")] [Register ("dismissKeyboardShortcutsHelper", "()V", "", ApiSince = 24)] public unsafe void DismissKeyboardShortcutsHelper () { … } } Some interesting notes: - `SupportedOSPlatformAttribute` is only available in .NET 5+, so we include a local version for earlier frameworks so we can compile without needing to `#ifdef` every attribute use. - The local version is marked as `[Conditional ("NEVER")]` so the attributes will not actually get compiled into the resulting pre-NET5.0 assembly. - The attribute cannot be placed on interfaces or fields, so we aren't able to annotate them. - Our minimum supported API for .NET 6 is 21, so we only write attributes for API added in versions newer than 21, as API added earlier are always available. [0]: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.versioning.supportedosplatformattribute?view=net-5.0
…)" (#841) Context: dotnet/android#5338 This reverts commit 00862ad. Now that we are properly building with `$(TargetFramework)`=net6.0 (4d0cba6), we can re-enable the `[SupportedOSPlatform]` support, as originally introduced in da12df4. Emit the [`System.Runtime.Versioning.SupportedOSPlatformAttribute`][0] custom attribute which is used to specify on which platforms and platform versions an API is available. This is used to build analyzers to give users warnings if they are trying to use an API when it will not be available on their target platform. [0]: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.versioning.supportedosplatformattribute?view=net-5.0
This has been implemented in Java.Interop: And bumped in XA: |
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
The text was updated successfully, but these errors were encountered: