diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AOTTemplateTest.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AOTTemplateTest.cs index 7858ec9b8491..1358868f679b 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AOTTemplateTest.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AOTTemplateTest.cs @@ -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) @@ -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) @@ -168,9 +168,9 @@ private List PrepareNativeAotBuildPropsWindows(string runtimeIdentifier) return extendedBuildProps; } - private List PrepareNativeAotBuildPropsAndroid() + internal static List PrepareNativeAotBuildPropsAndroid(List buildProps) { - var extendedBuildProps = new List(BuildProps) + var extendedBuildProps = new List(buildProps) { "PublishAot=true", "PublishAotUsingRuntimePack=true", diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AndroidTemplateTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AndroidTemplateTests.cs index a4115a3f182d..4b6eea0ba2d3 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AndroidTemplateTests.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AndroidTemplateTests.cs @@ -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"; + + 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");