Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using NUnit.Framework;
Expand Down Expand Up @@ -36,6 +37,56 @@ public void Build_WithTrimmableTypeMap_Succeeds ([Values] bool isRelease, [Value
AssertTrimmableTypeMapOutputs (intermediateDir);
}

[TestCase ("llvm-ir", AndroidRuntime.CoreCLR)]
[TestCase ("trimmable", AndroidRuntime.CoreCLR)]
[TestCase ("trimmable", AndroidRuntime.NativeAOT)]
public void Build_JavaSourceSemanticParityFixture_Compiles (
string typeMapImplementation,
AndroidRuntime runtime)
{
bool isRelease = runtime == AndroidRuntime.NativeAOT;
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
return;
}

var fixtureProject = Path.Combine (
XABuildPaths.TopDirectory,
"tests",
"Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests",
"JavaSourceParityFixture",
"JavaSourceParityFixture.csproj");
var proj = new XamarinAndroidApplicationProject {
IsRelease = isRelease,
References = {
new BuildItem.ProjectReference (fixtureProject, "JavaSourceParityFixture"),
new BuildItem.Reference ("Mono.Android.Export"),
},
};
proj.SetRuntime (runtime);
proj.SetProperty ("AndroidTypeMapImplementation", typeMapImplementation);
proj.MainActivity = proj.DefaultMainActivity.Replace (
"//${AFTER_ONCREATE}",
"System.GC.KeepAlive (new UserApp.JavaSourceParity.SemanticPeer ());");
proj.AndroidJavaSources.Add (new AndroidItem.AndroidJavaSource ("com\\example\\parity\\Base.java") {
Encoding = Encoding.ASCII,
TextContent = () => """
package com.example.parity;

public class Base {
public Base () {}
public Base (int value) {}
public java.lang.String getValue () { return ""; }
}
""",
});
using var builder = CreateApkBuilder ();
Assert.IsTrue (builder.Build (proj), $"{runtime}/{typeMapImplementation} should compile the shared semantic parity fixture.");

var compiledClass = builder.Output.GetIntermediaryPath (
Path.Combine ("android", "bin", "classes", "com", "example", "parity", "SemanticPeer.class"));
FileAssert.Exists (compiledClass, $"{runtime}/{typeMapImplementation} should compile the generated SemanticPeer Java source.");
}

[Test]
public void Build_PublishAotProject_UsesTrimmableTypeMapForCoreClrDebug ()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\Configuration.props" />

<PropertyGroup>
<TargetFramework>$(DotNetTargetFramework)</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<OutputType>Library</OutputType>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\product.snk</AssemblyOriginatorKeyFile>
<OutputPath>..\..\..\bin\Test$(Configuration)\</OutputPath>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Mono.Android\Mono.Android.csproj"
ReferenceOutputAssembly="false" />
</ItemGroup>

<Target Name="_AddMonoAndroidReference" BeforeTargets="ResolveAssemblyReferences">
<ItemGroup>
<_MonoAndroidRefCandidate
Condition=" '%(AndroidBuildApiLevel.Unstable)' == 'false' "
Include="$(MSBuildThisFileDirectory)..\..\..\bin\$(Configuration)\lib\packs\Microsoft.Android.Ref.%(AndroidBuildApiLevel.Identity)\*\ref\net*\Mono.Android.dll"
/>
<_JavaInteropRefCandidate
Condition=" '%(AndroidBuildApiLevel.Unstable)' == 'false' "
Include="$(MSBuildThisFileDirectory)..\..\..\bin\$(Configuration)\lib\packs\Microsoft.Android.Ref.%(AndroidBuildApiLevel.Identity)\*\ref\net*\Java.Interop.dll"
/>
</ItemGroup>
<PropertyGroup>
<_MonoAndroidRefAssembly>@(_MonoAndroidRefCandidate, ';')</_MonoAndroidRefAssembly>
<_MonoAndroidRefAssembly>$(_MonoAndroidRefAssembly.Split(';')[0])</_MonoAndroidRefAssembly>
<_JavaInteropRefAssembly>@(_JavaInteropRefCandidate, ';')</_JavaInteropRefAssembly>
<_JavaInteropRefAssembly>$(_JavaInteropRefAssembly.Split(';')[0])</_JavaInteropRefAssembly>
</PropertyGroup>
<ItemGroup Condition=" '$(_MonoAndroidRefAssembly)' != '' ">
<Reference Include="Mono.Android">
<HintPath>$(_MonoAndroidRefAssembly)</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(_JavaInteropRefAssembly)' != '' ">
<Reference Include="Java.Interop">
<HintPath>$(_JavaInteropRefAssembly)</HintPath>
</Reference>
</ItemGroup>
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Runtime.Versioning;
using Android.Runtime;
using Java.Interop;

[assembly: SupportedOSPlatform ("android24.0")]

namespace UserApp.JavaSourceParity;

[Register ("com/example/parity/Base", DoNotGenerateAcw = true)]
public class Base : Java.Lang.Object
{
protected Base (IntPtr handle, JniHandleOwnership transfer) : base (handle, transfer) { }

[Register (".ctor", "()V", "")]
public Base () { }

[Register (".ctor", "(I)V", "")]
public Base (int value) { }

[Register ("getValue", "()Ljava/lang/String;", "GetGetValueHandler")]
public virtual string GetValue () => "";
}

[Register ("com/example/parity/SemanticPeer")]
public class SemanticPeer : Base, Android.Views.View.IOnClickListener, Android.Views.View.IOnLongClickListener
{
public SemanticPeer () { }

public SemanticPeer (int value) : base (value) { }

public override string GetValue () => "derived";

public void OnClick (Android.Views.View? view) { }

public bool OnLongClick (Android.Views.View? view) => true;

[Export ("checkedExport", Throws = new [] { typeof (Java.IO.IOException) })]
protected int CheckedExport (string value) => value.Length;

[ExportField ("STATIC_LABEL")]
public static string GetStaticLabel () => "static";

[ExportField ("LABEL")]
public string GetLabel () => "instance";
}
Loading
Loading