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.91k stars 526 forks source link

Fix known issues with NativeAOT #8724

Open jonathanpeppers opened 6 months ago

jonathanpeppers commented 6 months ago

Android application type

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

Affected platform version

.NET 9+

Description

Related: https://github.com/xamarin/java.interop/issues/1192 Related: https://github.com/xamarin/java.interop/issues/1157

When setting $(EnableAotAnalyzer) to true, there are several warnings we will suppress for now. These will likely work under Mono, but will need to be fixed one day in .NET 10 or some future release that supports NativeAOT.

Ignoring AOT warnings like a reasonable place to start, so we can enable the analyzer and not introduce new warnings.

Creating an issue for now, so I can link to this issue from C# code comments.

Steps to Reproduce

Build Mono.Android.csproj with EnableAotAnalyzer=true.

Did you find any workaround?

No response

Relevant log output

No response

jonathanpeppers commented 6 months ago

Update

We'll probably actually suppress the warnings like:

// FIXME: https://github.com/xamarin/xamarin-android/issues/8724
// IL3050 disabled in source: if someone uses NativeAOT, they will get the warning.
#pragma warning disable IL3050
var dynamic = new DynamicMethod (DynamicMethodNameCounter.GetUniqueName (), ret_type, param_types, typeof (DynamicMethodNameCounter), true);
#pragma warning restore IL3050
jonathanpeppers commented 1 month ago

We will need to suppress warnings from the trimmer, but rely on warnings coming from the AOT compiler (ILC):