Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to xamarin/Java.Interop/main@bbaeda6f #7799

Merged
merged 3 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion build-tools/scripts/Jar.targets
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@
<_DestDir>$(IntermediateOutputPath)__CreateTestJarFile-bin</_DestDir>
<_AndroidJar>-bootclasspath "$(AndroidSdkDirectory)\platforms\android-$(_AndroidApiLevelName)\android.jar"</_AndroidJar>
<_CP>-cp "$(_JavaInteropJarPath)"</_CP>
<_JavacFilesResponse>$(IntermediateOutputPath)__javac_response.txt</_JavacFilesResponse>
</PropertyGroup>
<WriteLinesToFile
File="$(_JavacFilesResponse)"
Lines="@(_JavacSource)"
Overwrite="True"
/>
<MakeDir Directories="$(_DestDir)" />
<Exec Command="$(_Javac) $(_Targets) -d &quot;$(_DestDir)&quot; $(_AndroidJar) $(_CP) @(_JavacSource->'&quot;%(Identity)&quot;', ' ')" />
<Exec Command="$(_Javac) $(_Targets) -d &quot;$(_DestDir)&quot; $(_AndroidJar) $(_CP) &quot;@$(_JavacFilesResponse)&quot;" />
<Delete Files="$(_JavacFilesResponse)" />
<Exec
Command="$(_Jar) cf &quot;classes.jar&quot; ."
WorkingDirectory="$(_DestDir)"
Expand Down
2 changes: 1 addition & 1 deletion external/Java.Interop
7 changes: 5 additions & 2 deletions src/Mono.Android/Android.Runtime/AndroidRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,12 @@ protected override IEnumerable<string> 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,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static class ResourceData
static Lazy<byte []> javaSourceTestInterface = new Lazy<byte []> (() => GetResourceData ("JavaSourceTestInterface.java"));
static Lazy<byte []> remapActivityJava = new Lazy<byte []> (() => GetResourceData ("RemapActivity.java"));
static Lazy<byte []> remapActivityXml = new Lazy<byte []> (() => GetResourceData ("RemapActivity.xml"));
static Lazy<byte []> idmStaticMethodsInterface = new Lazy<byte []> (() => GetResourceData ("StaticMethodsInterface.java"));

public static byte[] JavaSourceJarTestJar => javaSourceJarTestJar.Value;
public static byte[] JavaSourceJarTestSourcesJar => javaSourceJarTestSourcesJar.Value;
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<EmbeddedResource Include="Resources\RemapActivity*">
<LogicalName>%(FileName)%(Extension)</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Resources\StaticMethodsInterface*">
<LogicalName>%(FileName)%(Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package example;

public interface StaticMethodsInterface {
static int getValue() {
return 3;
}
}
53 changes: 53 additions & 0 deletions tests/MSBuildDeviceIntegration/Tests/XASdkDeployTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<replace-type
from="com/xamarin/interop/RenameClassBase1"
to="com/xamarin/interop/RenameClassBase2" />
<replace-type
from="com/xamarin/interop/AndroidInterface"
to="com/xamarin/interop/DesugarAndroidInterface$_CC" />
<replace-method
source-type="java/lang/Object"
source-method-name="remappedToToString"
Expand Down