dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.94k stars 533 forks source link

Duplicate RequireViewById #7983

Closed rgroenewoudt closed 1 year ago

rgroenewoudt commented 1 year ago

Android application type

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

Affected platform version

VS2022 17.5.4, .NET 7 Android

Description

View currently has 2 methods RequireViewById:

[SupportedOSPlatform("android28.0")]
[Register("requireViewById", "(I)Landroid/view/View;", "", ApiSince = 28)]
[JavaTypeParameters(new string[] {"T extends android.view.View"})]
public Java.Lang.Object RequireViewById(int id);

and

public T RequireViewById<T>(int id) where T : View;

The first one is coming from Android bindings, the 2nd is added by Xamarin. This might be a case where hiding the Android method might be better as the Xamarin version will be better due being supported < API 28 and returning the View and not a Java.Lang.Object which needs to be casted.

Steps to Reproduce

-

Did you find any workaround?

No response

Relevant log output

No response

jpobst commented 1 year ago

Unfortunately, there is basically never a case where we remove public shipping API, as it breaks any code that is using that method. Since this method has been around for ~5 major Android versions, that's likely a significant amount of code.

rgroenewoudt commented 1 year ago

I'll use something like Microsoft.CodeAnalysis.BannedApiAnalyzers instead to ban the use of Android's RequireViewById.