xamarin / java.interop

Java.Interop provides open-source bindings of Java's Java Native Interface (JNI) for use with .NET managed languages such as C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java bindings incorrectly assigning method as obsolete

Archit-Pikle opened this issue · comments

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

VS 17.8.0 Preview 1.0

Description

Java bindings are tagging a method as Obsolete even though the api.xml sets it as not deprecated

Our Java bindings are failing with the following error -
Error CS0809 Obsolete member 'MAMIntentService.OnBind(Intent?)' overrides non-obsolete member 'Service.OnBind(Intent?)'

I see the api.xml is correctly tagging the method as not deprecated -

<method abstract="false" deprecated="not deprecated" final="true" name="onBind" jni-signature="(Landroid/content/Intent;)Landroid/os/IBinder;" bridge="false" native="false" return="android.os.IBinder" jni-return="Landroid/os/IBinder;" static="false" synchronized="false" synthetic="false" visibility="public">
        <parameter name="intent" type="android.content.Intent" jni-type="Landroid/content/Intent;" />
      </method>

The generated MAMIntentService.cs file is tagging the method as obsolete -

[global::System.Obsolete (@"deprecated")]
[Register ("onBind", "(Landroid/content/Intent;)Landroid/os/IBinder;", "")]
public override sealed unsafe global::Android.OS.IBinder? OnBind (global::Android.Content.Intent? intent)

This is only happening on .NET 8 and started occurring with the latest release.

Steps to Reproduce

N/A

Did you find any workaround?

No response

Relevant log output

No response

My guess would be something to do with #1130.

Can you provide the full api.xml?

Also note that it is simply a warning, and you are likely using some form of "warnings as errors" feature to turn it into an error.

Here's the zip containing the api.xml
api.zip

Thanks for the note. We are treating warnings as errors in our project

It looks like MAMIntentService inherits from Android.App.IntentService:

<class abstract="true" deprecated="not deprecated" extends="android.app.IntentService" extends-generic-aware="android.app.IntentService" jni-extends="Landroid/app/IntentService;" final="false" name="MAMIntentService" static="false" visibility="public" jni-signature="Lcom/microsoft/intune/mam/client/app/MAMIntentService;">
  <method abstract="false" deprecated="not deprecated" final="true" name="onBind" jni-signature="(Landroid/content/Intent;)Landroid/os/IBinder;" bridge="false" native="false" return="android.os.IBinder" jni-return="Landroid/os/IBinder;" static="false" synchronized="false" synthetic="false" visibility="public">
    <parameter name="intent" type="android.content.Intent" jni-type="Landroid/content/Intent;" />
  </method>
  ...
</class>

And Android.App.IntentService and its OnBind are indeed [Obsolete]:

The interesting thing is that according to your error message, MAMIntentService is inheriting Android.App.Service instead:

Obsolete member 'MAMIntentService.OnBind(Intent?)' overrides non-obsolete member 'Service.OnBind(Intent?)' 

Are you doing something custom that remaps the base class of MAMIntentService?

The java class Android.App.IntentService does extend Android.App.Service and it's onBind doesn't seem to be deprecated
https://developer.android.com/reference/android/app/IntentService

https://developer.android.com/reference/android/app/Service#onBind(android.content.Intent)

The java class Android.App.IntentService does extend Android.App.Service and it's onBind doesn't seem to be deprecated

Agreed, but the issue is MAMIntentService extends IntentService which is deprecated, not Service.

Why does the Java MAMIntentService extend IntentService but the C# MAMIntentService extends Service?

(Note that this feature (like all of generator) works solely on the Java API side. It does not build a C# model so it does not take any C# base classes into account.)

It feels like this feature is working as intended, however there are scenarios where the feature is undesired, and we need to provide a way to opt out of it.