Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void PublishNativeAOT(string id, string framework, string runtimeIdentifi
var extendedBuildProps = isWindowsFramework
? PrepareNativeAotBuildPropsWindows(runtimeIdentifier)
: isAndroidPlatform
? PrepareNativeAotBuildPropsAndroid()
? PrepareNativeAotBuildPropsAndroid(BuildProps)
: PrepareNativeAotBuildProps();

// Disable code signing for Apple platforms (no signing certificate available in CI)
Expand Down Expand Up @@ -93,7 +93,7 @@ public void PublishNativeAOTRootAllMauiAssemblies(string id, string framework, s
var extendedBuildProps = isWindowsFramework
? PrepareNativeAotBuildPropsWindows(runtimeIdentifier)
: isAndroidPlatform
? PrepareNativeAotBuildPropsAndroid()
? PrepareNativeAotBuildPropsAndroid(BuildProps)
: PrepareNativeAotBuildProps();

// Disable code signing for Apple platforms (no signing certificate available in CI)
Expand Down Expand Up @@ -168,9 +168,9 @@ private List<string> PrepareNativeAotBuildPropsWindows(string runtimeIdentifier)
return extendedBuildProps;
}

private List<string> PrepareNativeAotBuildPropsAndroid()
internal static List<string> PrepareNativeAotBuildPropsAndroid(List<string> buildProps)
{
var extendedBuildProps = new List<string>(BuildProps)
var extendedBuildProps = new List<string>(buildProps)
{
"PublishAot=true",
"PublishAotUsingRuntimePack=true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,44 @@ public void RunOnAndroid(string id, string framework, string config, string? tri
$"Project {Path.GetFileName(projectFile)} failed to run. Check test output/attachments for errors.");
}

[Fact]
public void RunOnAndroid_MauiNativeAOT()
{
var id = "maui";
var framework = DotNetCurrent;
var config = "Release";
Comment thread
sbomer marked this conversation as resolved.

SetTestIdentifier(id, framework, config, "NativeAOT");
var projectDir = TestDirectory;
var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj");

Assert.True(DotnetInternal.New(id, projectDir, framework, output: _output),
$"Unable to create template {id}. Check test output for errors.");

var buildProps = AOTTemplateTest.PrepareNativeAotBuildPropsAndroid(BuildProps);

// Restrict to Android-only to avoid restoring NativeAOT packages for other platforms (e.g., iOS)
// which may not be available in the configured NuGet sources
buildProps.Add($"TargetFrameworks={framework}-android");

// NativeAOT requires an explicit runtime identifier matching the emulator ABI
var runtimeIdentifier = _emulatorFixture.TestAvd.Abi == "arm64-v8a" ? "android-arm64" : "android-x64";

AddInstrumentation(projectDir);

Assert.True(DotnetInternal.Build(projectFile, config, target: "Install", framework: $"{framework}-android",
properties: buildProps, runtimeIdentifier: runtimeIdentifier, output: _output),
$"Project {Path.GetFileName(projectFile)} failed to build and install. Check test output/attachments for errors.");

// Write xh-results to the log directory for artifact collection
var xhResultsDir = Path.Combine(TestEnvironment.GetLogDirectory(), "xh-results", Path.GetFileName(projectDir));
Directory.CreateDirectory(xhResultsDir);

testPackage = $"com.companyname.{Path.GetFileName(projectDir).ToLowerInvariant()}";
Assert.True(XHarness.RunAndroid(testPackage, xhResultsDir, -1, output: _output),
$"Project {Path.GetFileName(projectFile)} failed to run. Check test output/attachments for errors.");
}

void AddInstrumentation(string projectDir)
{
var androidDir = Path.Combine(projectDir, "Platforms", "Android");
Expand Down
Loading