diff --git a/build-tools/scripts/Jar.targets b/build-tools/scripts/Jar.targets index 75a0c533218..477afd8612c 100644 --- a/build-tools/scripts/Jar.targets +++ b/build-tools/scripts/Jar.targets @@ -35,9 +35,16 @@ <_DestDir>$(IntermediateOutputPath)__CreateTestJarFile-bin <_AndroidJar>-bootclasspath "$(AndroidSdkDirectory)\platforms\android-$(_AndroidApiLevelName)\android.jar" <_CP>-cp "$(_JavaInteropJarPath)" + <_JavacFilesResponse>$(IntermediateOutputPath)__javac_response.txt + - + + GetSimpleReferences (Type type) desugarType.Append ("Desugar").Append (name); } + var typeWithPrefix = desugarType.ToString (); + var typeWithSuffix = $"{jniSimpleReference}$-CC"; + return new[]{ - desugarType.ToString (), - $"{jniSimpleReference}$-CC" + GetReplacementTypeCore (typeWithPrefix) ?? typeWithPrefix, + GetReplacementTypeCore (typeWithSuffix) ?? typeWithSuffix, }; } diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/ResourceData.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/ResourceData.cs index 177d2315eff..051916cc258 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/ResourceData.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/ResourceData.cs @@ -21,6 +21,7 @@ static class ResourceData static Lazy javaSourceTestInterface = new Lazy (() => GetResourceData ("JavaSourceTestInterface.java")); static Lazy remapActivityJava = new Lazy (() => GetResourceData ("RemapActivity.java")); static Lazy remapActivityXml = new Lazy (() => GetResourceData ("RemapActivity.xml")); + static Lazy idmStaticMethodsInterface = new Lazy (() => GetResourceData ("StaticMethodsInterface.java")); public static byte[] JavaSourceJarTestJar => javaSourceJarTestJar.Value; public static byte[] JavaSourceJarTestSourcesJar => javaSourceJarTestSourcesJar.Value; @@ -34,6 +35,7 @@ static class ResourceData public static string JavaSourceTestInterface => Encoding.ASCII.GetString (javaSourceTestInterface.Value); public static string RemapActivityJava => Encoding.UTF8.GetString (remapActivityJava.Value); public static string RemapActivityXml => Encoding.UTF8.GetString (remapActivityXml.Value); + public static string IdmStaticMethodsInterface => Encoding.UTF8.GetString (idmStaticMethodsInterface.Value); static byte[] GetResourceData (string name) { diff --git a/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj b/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj index d6bb578c27b..cf067e4e5b5 100644 --- a/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj +++ b/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj @@ -31,6 +31,9 @@ %(FileName)%(Extension) + + %(FileName)%(Extension) + diff --git a/tests/MSBuildDeviceIntegration/Resources/StaticMethodsInterface.java b/tests/MSBuildDeviceIntegration/Resources/StaticMethodsInterface.java new file mode 100644 index 00000000000..1b8e157b758 --- /dev/null +++ b/tests/MSBuildDeviceIntegration/Resources/StaticMethodsInterface.java @@ -0,0 +1,7 @@ +package example; + +public interface StaticMethodsInterface { + static int getValue() { + return 3; + } +} diff --git a/tests/MSBuildDeviceIntegration/Tests/XASdkDeployTests.cs b/tests/MSBuildDeviceIntegration/Tests/XASdkDeployTests.cs index 68eb6d66170..f97e3e7d85b 100644 --- a/tests/MSBuildDeviceIntegration/Tests/XASdkDeployTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/XASdkDeployTests.cs @@ -155,6 +155,59 @@ public void TypeAndMemberRemapping ([Values (false, true)] bool isRelease) ); } + [Test] + public void SupportDesugaringStaticInterfaceMethods () + { + AssertHasDevices (); + if (!Builder.UseDotNet) { + Assert.Ignore ("Skipping. Test not relevant under Classic."); + } + + var proj = new XASdkProject () { + IsRelease = true, + OtherBuildItems = { + new AndroidItem.AndroidJavaSource ("StaticMethodsInterface.java") { + Encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false), + TextContent = () => ResourceData.IdmStaticMethodsInterface, + Metadata = { + { "Bind", "True" }, + }, + }, + }, + }; + + // Note: To properly test, Desugaring must be *enabled*, which requires that + // `$(SupportedOSPlatformVersion)` be *less than* 23. 21 is currently the default, + // but set this explicitly anyway just so that this implicit requirement is explicit. + proj.SetProperty (proj.ReleaseProperties, "SupportedOSPlatformVersion", "21"); + + proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", @" + Console.WriteLine ($""# jonp static interface default method invocation; IStaticMethodsInterface.Value={Example.IStaticMethodsInterface.Value}""); +"); + proj.SetRuntimeIdentifier (DeviceAbi); + var relativeProjDir = Path.Combine ("temp", TestName); + var fullProjDir = Path.Combine (Root, relativeProjDir); + TestOutputDirectories [TestContext.CurrentContext.Test.ID] = fullProjDir; + var files = proj.Save (); + proj.Populate (relativeProjDir, files); + proj.CopyNuGetConfig (relativeProjDir); + var dotnet = new DotNetCLI (proj, Path.Combine (fullProjDir, proj.ProjectFilePath)); + + Assert.IsTrue (dotnet.Build (), "`dotnet build` should succeed"); + Assert.IsTrue (dotnet.Run (), "`dotnet run` should succeed"); + + bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity", + Path.Combine (fullProjDir, "logcat.log")); + Assert.IsTrue (didLaunch, "MainActivity should have launched!"); + var logcatOutput = File.ReadAllText (Path.Combine (fullProjDir, "logcat.log")); + + StringAssert.Contains ( + "IStaticMethodsInterface.Value=3", + logcatOutput, + "Was IStaticMethodsInterface.Value executed?" + ); + } + [Test] [Category ("Debugger"), Category ("Node-4")] public void DotNetDebug ([Values("net6.0-android", "net7.0-android")] string targetFramework) diff --git a/tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Remaps.xml b/tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Remaps.xml index 6238cdc346a..5324e8e189f 100644 --- a/tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Remaps.xml +++ b/tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Remaps.xml @@ -2,6 +2,9 @@ +