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 more Mono.Android.dll linker warnings (#6270)
Context: dotnet/linker#2265 Context: #5652 There are two remaining linker warnings when building with `$(SuppressTrimAnalysisWarnings)`=false: > 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`. Use `[UnconditionalSuppressMessage]` to ignore the warning, because the assembly hitting the warning is the "root assembly", which is *not linked*. The methods in question will not be removed by the linker. 2. `JavaObjectExtensions.GetHelperType()` dynamically looks up `*Invoker` types. Use `[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 Adding `-p:TrimmerSingleWarn=false` shows an additional 30 warnings.
- Loading branch information