diff --git a/src/Mono.Android/Android.Runtime/ResourceIdManager.cs b/src/Mono.Android/Android.Runtime/ResourceIdManager.cs index 3c524bcab61..4a9590dcba4 100644 --- a/src/Mono.Android/Android.Runtime/ResourceIdManager.cs +++ b/src/Mono.Android/Android.Runtime/ResourceIdManager.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Reflection; namespace Android.Runtime @@ -30,6 +31,7 @@ public static void UpdateIdValues () } } + [UnconditionalSuppressMessage ("Trimming", "IL2026", Justification = "Types in Resource.designer.cs are preserved, because it is the root assembly passed to the linker.")] static Type? GetResourceTypeFromAssembly (Assembly assembly) { foreach (var customAttribute in assembly.GetCustomAttributes (typeof (ResourceDesignerAttribute), true)) { diff --git a/src/Mono.Android/Java.Interop/JavaObjectExtensions.cs b/src/Mono.Android/Java.Interop/JavaObjectExtensions.cs index d314643b525..52bb990f249 100644 --- a/src/Mono.Android/Java.Interop/JavaObjectExtensions.cs +++ b/src/Mono.Android/Java.Interop/JavaObjectExtensions.cs @@ -92,7 +92,7 @@ static IJavaObject CastClass (IJavaObject instance, Type resultType) if (resultType.IsAbstract) { // TODO: keep in sync with TypeManager.CreateInstance() algorithm - var invokerType = GetHelperType (resultType, "Invoker"); + var invokerType = GetInvokerType (resultType); if (invokerType == null) throw new ArgumentException ("Unable to get Invoker for abstract type '" + resultType.FullName + "'.", "TResult"); resultType = invokerType; @@ -122,10 +122,12 @@ static IJavaObject CastClass (IJavaObject instance, Type resultType) instance.GetType ().FullName, resultType.FullName)); } - // typeof(Foo) -> FooSuffix - // typeof(Foo<>) -> FooSuffix`1 - internal static Type? GetHelperType (Type type, string suffix) + // typeof(Foo) -> FooInvoker + // typeof(Foo<>) -> FooInvoker`1 + [UnconditionalSuppressMessage ("Trimming", "IL2026", Justification = "*Invoker types are preserved by the MarkJavaObjects linker step.")] + internal static Type? GetInvokerType (Type type) { + const string suffix = "Invoker"; Type[] arguments = type.GetGenericArguments (); if (arguments.Length == 0) return type.Assembly.GetType (type + suffix); diff --git a/src/Mono.Android/Java.Interop/TypeManager.cs b/src/Mono.Android/Java.Interop/TypeManager.cs index be95be97a8a..5476bd15f29 100644 --- a/src/Mono.Android/Java.Interop/TypeManager.cs +++ b/src/Mono.Android/Java.Interop/TypeManager.cs @@ -292,7 +292,7 @@ internal static IJavaPeerable CreateInstance (IntPtr handle, JniHandleOwnership type = targetType; if (type.IsInterface || type.IsAbstract) { - var invokerType = JavaObjectExtensions.GetHelperType (type, "Invoker"); + var invokerType = JavaObjectExtensions.GetInvokerType (type); if (invokerType == null) throw new NotSupportedException ("Unable to find Invoker for type '" + type.FullName + "'. Was it linked away?", CreateJavaLocationException ()); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs index 4d3610fbcad..0acfe412ccc 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs @@ -200,12 +200,25 @@ public Foo () [Test] public void DotNetNew ([Values ("android", "androidlib", "android-bindinglib")] string template) { + var parameters = new List { + // TODO: Uncomment after warnings are solved + // 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 + //"SuppressTrimAnalysisWarnings=false" + }; var dotnet = CreateDotNetBuilder (); Assert.IsTrue (dotnet.New (template), $"`dotnet new {template}` should succeed"); File.WriteAllBytes (Path.Combine (dotnet.ProjectDirectory, "foo.jar"), ResourceData.JavaSourceJarTestJar); Assert.IsTrue (dotnet.New ("android-activity"), "`dotnet new android-activity` should succeed"); Assert.IsTrue (dotnet.New ("android-layout", Path.Combine (dotnet.ProjectDirectory, "Resources", "layout")), "`dotnet new android-layout` should succeed"); - Assert.IsTrue (dotnet.Build (), "`dotnet build` should succeed"); + + // Debug build + Assert.IsTrue (dotnet.Build (parameters: parameters.ToArray ()), "`dotnet build` should succeed"); + dotnet.AssertHasNoWarnings (); + + // Release build + parameters.Add ("Configuration=Release"); + Assert.IsTrue (dotnet.Build (parameters: parameters.ToArray ()), "`dotnet build` should succeed"); dotnet.AssertHasNoWarnings (); }