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 @@ -13,8 +13,8 @@ This file contains the CoreCLR-specific MSBuild logic for .NET for Android.
</PropertyGroup>
<!-- Properties for $(OutputType)=Exe (Android Applications) -->
<PropertyGroup Condition=" '$(AndroidApplication)' == 'true' ">
<!-- Default to R2R Composite for CoreCLR Release mode -->
<PublishReadyToRun Condition=" '$(PublishReadyToRun)' == '' and '$(Configuration)' == 'Release' ">true</PublishReadyToRun>
<!-- Default to R2R Composite for CoreCLR Release mode or when publishing -->
<PublishReadyToRun Condition=" '$(PublishReadyToRun)' == '' and ('$(Configuration)' == 'Release' or '$(_IsPublishing)' == 'true') ">true</PublishReadyToRun>
<PublishReadyToRunComposite Condition=" '$(PublishReadyToRunComposite)' == '' and '$(PublishReadyToRun)' == 'true' ">true</PublishReadyToRunComposite>
<_IsPublishing Condition=" '$(_IsPublishing)' == '' and '$(PublishReadyToRun)' == 'true' ">true</_IsPublishing>
<AllowReadyToRunWithoutRuntimeIdentifier Condition=" '$(PublishReadyToRun)' == 'true' and '$(RuntimeIdentifiers)' != '' ">true</AllowReadyToRunWithoutRuntimeIdentifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Xml.Linq;
using System.Reflection;
using System.Reflection.PortableExecutable;
using System.Text;
using NUnit.Framework;
using Xamarin.Android.Tools;
Expand Down Expand Up @@ -279,6 +280,37 @@ public void DotNetPublishDefaultValues ([Values] bool isRelease, [Values] Androi
Assert.IsTrue (dotnet.Publish (), "`dotnet publish` should succeed");
}

[Test]
public void DotNetPublishReadyToRunCustomConfiguration ()
{
const string runtimeIdentifier = "android-arm64";
var proj = new XamarinAndroidApplicationProject ();
proj.SetRuntime (AndroidRuntime.CoreCLR);
proj.SetProperty (KnownProperties.RuntimeIdentifier, runtimeIdentifier);
proj.SetProperty ("AndroidEnableAssemblyCompression", "false");

var builder = CreateDllBuilder ();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot why does this call CreateDllBuilder()? should it be CreateApkBuilder() for an application project?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It follows the pattern used by the other tests in this file (DotNetPublishDefaultValues at line 277, DotNetPublish at line 352, etc.) — the builder is only used to save the project to disk via builder.Save(proj), and the actual publish is done through DotNetCLI.Publish(). All tests in XASdkTests.cs use CreateDllBuilder() for this purpose. Happy to change it if you'd prefer a different approach though.

builder.Save (proj);
var dotnet = new DotNetCLI (Path.Combine (Root, builder.ProjectDirectory, proj.ProjectFilePath));
Assert.IsTrue (dotnet.Publish (parameters: new [] { "Configuration=CustomRelease" }), "`dotnet publish -c CustomRelease` should succeed");

var assemblyName = proj.ProjectName;
// Configuration=CustomRelease produces output under bin/CustomRelease/
var publishDirectory = Path.Combine (Root, builder.ProjectDirectory, "bin", "CustomRelease", runtimeIdentifier, "publish");
var apkSigned = Path.Combine (publishDirectory, $"{proj.PackageName}-Signed.apk");
FileAssert.Exists (apkSigned);

var helper = new ArchiveAssemblyHelper (apkSigned, true);
var abi = MonoAndroidHelper.RidToAbi (runtimeIdentifier);
Assert.IsTrue (helper.Exists ($"assemblies/{abi}/{assemblyName}.dll"), $"{assemblyName}.dll should exist in apk!");

using var stream = helper.ReadEntry ($"assemblies/{assemblyName}.dll");
stream.Position = 0;
using var peReader = new PEReader (stream);
Assert.IsTrue (peReader.PEHeaders.CorHeader.ManagedNativeHeaderDirectory.Size > 0,
$"ReadyToRun image not found in {assemblyName}.dll! ManagedNativeHeaderDirectory should not be empty!");
}

[Test]
public void DotNetPublish ([Values] bool isRelease, [ValueSource (nameof(Get_DotNetTargetFrameworks_Data))] object[] data)
{
Expand Down
Loading