dotnet / java-interop

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

[Java.Interop] ignore remaining trimming warnings #1190

Closed jonathanpeppers closed 5 months ago

jonathanpeppers commented 5 months ago

Fixes: https://github.com/xamarin/java.interop/issues/1157

The remaining trimmer warnings are around usage of System.Reflection such as:

The trimming warnings themselves all indicate that these types "might be trimmed", in that nothing explicitly preserves them. However, we have a plethora of custom trimmer steps that work to preserve these types involved in Java interop, such as:

One day, in a perfect world, we could remove these trimmer steps and completely rely on the trimmer's warnings & attributing mechanisms. That day doesn't have to be today -- as our goal is begin surfacing trimmer warnings to users in their own code and dependencies.

With these warnings ignored, we can fully enable analyzers with:

<IsTrimmable>true</IsTrimmable>
<EnableAotAnalyzer>true</EnableAotAnalyzer>

We can then remove:

[assembly: AssemblyMetadata ("IsTrimmable", "True")]

As the MSBuild property does this for us, in addition to enabling analyzers.

I don't think we should enable $(IsAotCompatible) quite yet, as Java.Interop.dll likely won't work yet on NativeAOT, and this places metadata that says an assembly is supported. We should just use the $(EnableAotAnalyzer) analyzers for now, so we don't introduce new issues.

jonathanpeppers commented 5 months ago

/cc @simonrozsival @vitek-karas