Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[One .NET] fix remaining Mono.Android.dll linker warnings
Fixes: dotnet#5652 There are two remaining linker warnings when building with: > dotnet build -c Release -p:SuppressTrimAnalysisWarnings=false ... src\Mono.Android\Android.Runtime\ResourceIdManager.cs(37,6): warning IL2026: Android.Runtime.ResourceIdManager.GetResourceTypeFromAssembly(Assembly): Using method 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed. src\Mono.Android\Java.Interop\JavaObjectExtensions.cs(136,4): warning IL2026: Java.Interop.JavaObjectExtensions.GetHelperType(Type,String): Using method 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed. src\Mono.Android\Java.Interop\JavaObjectExtensions.cs(131,5): warning IL2026: Java.Interop.JavaObjectExtensions.GetHelperType(Type,String): Using method 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed. The two issues here: 1. `ResourceIdManager` uses reflection for the implementation of `Resource.designer.cs`. Specify `UnconditionalSuppressMessage` to ignore the warning, because the assembly hitting the warning is the "root assembly". The methods in question will not be removed by the linker. 2. `JavaObjectExtensions.GetHelperType` dynamically looks up `Invoker` types. Specify `UnconditionalSuppressMessage` to ignore the warning, because the `MarkJavaObjects` linker step preserves them. Additionally, I renamed the method to `GetInvokerType()` and hardcoded `"Invoker"` within the method. This should prevent us from messing this up if a new "helper" type is added in addition to `Invoker`. Unfortunately, even after all the issues are solved. `ILLink` still appears to emit warnings: Java.Interop.dll warning IL2104: Assembly 'Java.Interop' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries Mono.Android.dll warning IL2104: Assembly 'Mono.Android' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries My guess is that `UnconditionalSuppressMessage` isn't clearing `IL2104` when it should be. I'll file an issue upstream in mono/linker about this.
- Loading branch information