Skip to content
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

Invokers should emit [SupportedOSPlatformAttribute] #863

Closed
jpobst opened this issue Jul 28, 2021 · 0 comments · Fixed by #868
Closed

Invokers should emit [SupportedOSPlatformAttribute] #863

jpobst opened this issue Jul 28, 2021 · 0 comments · Fixed by #868
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)

Comments

@jpobst
Copy link
Contributor

jpobst commented Jul 28, 2021

We began emitting [SupportedOSPlatformAttribute] for net6.0 Mono.Android.dll public API:

[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android23.0")]
[global::Android.Runtime.Register ("android/telecom/InCallService", DoNotGenerateAcw=true, ApiSince = 23)]
public abstract partial class InCallService : Android.App.Service { ... }

However our internal machinery uses this API without having the same guards:

[global::Android.Runtime.Register ("android/telecom/InCallService", DoNotGenerateAcw=true, ApiSince = 23)]
internal partial class InCallServiceInvoker : InCallService { ... }

This results in warnings:

…/xamarin-android/src/Mono.Android/obj/Release/net6.0/android-30/mcw/Android.Telecom.InCallService.cs(1287,76):
warning CA1416: This call site is reachable on all platforms. 'InCallService' is only supported on: 'android' 23.0 and later.

We need to emit the same [SupportedOSPlatformAttribute] for these methods as well.

@jpobst jpobst added enhancement Proposed change to current functionality generator Issues binding a Java library (generator, class-parse, etc.) bug Component does not function as intended and removed enhancement Proposed change to current functionality labels Jul 28, 2021
jonpryor pushed a commit that referenced this issue Aug 27, 2021
Fixes: #863

In commits da12df4 and 412e974 (and others) we added support to
emit the `[SupportedOSPlatformAttribute]` custom attribute when
targeting .NET 6+ builds, using the Android API-level that the member
was introduced:

	[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android23.0")]
	[global::Android.Runtime.Register ("android/telecom/InCallService", DoNotGenerateAcw=true, ApiSince = 23)]
	public abstract partial class InCallService : Android.App.Service {
	}

However, our "invoke" machinery uses this API without having the same
guards:

	[global::Android.Runtime.Register ("android/telecom/InCallService", DoNotGenerateAcw=true, ApiSince = 23)]
	internal partial class InCallServiceInvoker : InCallService {
	}

This results in build warnings when building e.g.
`xamarin-android/src/Mono.Android`:

	…/xamarin-android/src/Mono.Android/obj/Release/net6.0/android-30/mcw/Android.Telecom.InCallService.cs(1287,76):
	warning CA1416: This call site is reachable on all platforms. 'InCallService' is only supported on: 'android' 23.0 and later.

To fix these warnings, we need to emit the same
`[SupportedOSPlatformAttribute]` for these members as well:

	[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android23.0")]
	[global::Android.Runtime.Register ("android/telecom/InCallService", DoNotGenerateAcw=true, ApiSince = 23)]
	internal partial class InCallServiceInvoker : InCallService {
	}

This change removes 4,699 `CA1416` warnings from our
`Mono.Android.dll` build.

The remaining 61 `CA1416` warnings are of the form:

	…\xamarin-android\src\Mono.Android\obj\Debug\net6.0\android-31\mcw\Java.Lang.Reflect.Method.cs(35,71):
	warning CA1416: This call site is reachable on all platforms. 'Executable' is only supported on: 'android' 26.0 and later.

The problem here is that `Java.Lang.Reflect.Method` class is available
since API-1, but it inherits from the `Java.Lang.Reflect.Executable`
class which was added in API-26.

See:

  - https://developer.android.com/reference/java/lang/reflect/Method
  - https://developer.android.com/reference/java/lang/reflect/Executable

This seems like a `Mono.Android.dll` issue and not something we should
attempt to fix in `generator`.
jonpryor pushed a commit to xamarin/xamarin-android that referenced this issue Sep 8, 2021
jpobst added a commit that referenced this issue Sep 30, 2021
Fixes: #863

In commits da12df4 and 412e974 (and others) we added support to
emit the `[SupportedOSPlatformAttribute]` custom attribute when
targeting .NET 6+ builds, using the Android API-level that the member
was introduced:

	[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android23.0")]
	[global::Android.Runtime.Register ("android/telecom/InCallService", DoNotGenerateAcw=true, ApiSince = 23)]
	public abstract partial class InCallService : Android.App.Service {
	}

However, our "invoke" machinery uses this API without having the same
guards:

	[global::Android.Runtime.Register ("android/telecom/InCallService", DoNotGenerateAcw=true, ApiSince = 23)]
	internal partial class InCallServiceInvoker : InCallService {
	}

This results in build warnings when building e.g.
`xamarin-android/src/Mono.Android`:

	…/xamarin-android/src/Mono.Android/obj/Release/net6.0/android-30/mcw/Android.Telecom.InCallService.cs(1287,76):
	warning CA1416: This call site is reachable on all platforms. 'InCallService' is only supported on: 'android' 23.0 and later.

To fix these warnings, we need to emit the same
`[SupportedOSPlatformAttribute]` for these members as well:

	[global::System.Runtime.Versioning.SupportedOSPlatformAttribute ("android23.0")]
	[global::Android.Runtime.Register ("android/telecom/InCallService", DoNotGenerateAcw=true, ApiSince = 23)]
	internal partial class InCallServiceInvoker : InCallService {
	}

This change removes 4,699 `CA1416` warnings from our
`Mono.Android.dll` build.

The remaining 61 `CA1416` warnings are of the form:

	…\xamarin-android\src\Mono.Android\obj\Debug\net6.0\android-31\mcw\Java.Lang.Reflect.Method.cs(35,71):
	warning CA1416: This call site is reachable on all platforms. 'Executable' is only supported on: 'android' 26.0 and later.

The problem here is that `Java.Lang.Reflect.Method` class is available
since API-1, but it inherits from the `Java.Lang.Reflect.Executable`
class which was added in API-26.

See:

  - https://developer.android.com/reference/java/lang/reflect/Method
  - https://developer.android.com/reference/java/lang/reflect/Executable

This seems like a `Mono.Android.dll` issue and not something we should
attempt to fix in `generator`.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant