diff --git a/eng/pipelines/arcade/setup-test-env.yml b/eng/pipelines/arcade/setup-test-env.yml
index 18c62294314b..9e9c0d27d50b 100644
--- a/eng/pipelines/arcade/setup-test-env.yml
+++ b/eng/pipelines/arcade/setup-test-env.yml
@@ -11,6 +11,14 @@ steps:
fetchDepth: 1
clean: true
+# Enable KVM for Android tests on Linux
+- bash: |
+ echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
+ sudo udevadm control --reload-rules
+ sudo udevadm trigger --name-match=kvm
+ displayName: Enable KVM
+ condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))
+
- template: /eng/pipelines/common/provision.yml@self
parameters:
checkoutDirectory: '$(System.DefaultWorkingDirectory)'
diff --git a/src/DotNet/DotNet.csproj b/src/DotNet/DotNet.csproj
index 5cab15a090ed..4e4e92feec35 100644
--- a/src/DotNet/DotNet.csproj
+++ b/src/DotNet/DotNet.csproj
@@ -78,7 +78,9 @@
<_WorkloadSource Include="$(NugetArtifactsPath)" />
- <_LocalWorkloadIds Include="maui" />
+
+ <_LocalWorkloadIds Include="maui-android" Condition="$([MSBuild]::IsOSPlatform('linux'))" />
+ <_LocalWorkloadIds Include="maui" Condition="!$([MSBuild]::IsOSPlatform('linux'))" />
<_LocalWorkloadIds Include="tizen" Condition=" '$(IncludeTizenTargetFrameworks)' == 'true' " />
diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AndroidTemplateTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AndroidTemplateTests.cs
index 2e8027bcfdfd..a4115a3f182d 100644
--- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AndroidTemplateTests.cs
+++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AndroidTemplateTests.cs
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
+using System.Text.RegularExpressions;
using Microsoft.Maui.IntegrationTests.Android;
namespace Microsoft.Maui.IntegrationTests
@@ -94,6 +95,12 @@ public void RunOnAndroid(string id, string framework, string config, string? tri
Assert.True(DotnetInternal.New(id, projectDir, framework, output: _output),
$"Unable to create template {id}. Check test output for errors.");
+ // On Linux, only the maui-android workload is installed. Previous .NET
+ // templates may still include iOS/macOS TFMs causing NETSDK1178 errors
+ // during restore. Strip them so only Android remains.
+ if (TestEnvironment.IsLinux)
+ StripNonAndroidTfms(projectFile, framework);
+
var buildProps = BuildProps;
if (!string.IsNullOrEmpty(trimMode))
{
@@ -128,5 +135,20 @@ void AddInstrumentation(string projectDir)
"MainLauncher = true, Name = \"com.microsoft.mauitemplate.MainActivity\"");
}
+ static void StripNonAndroidTfms(string projectFile, string framework)
+ {
+ var content = File.ReadAllText(projectFile);
+ var androidTfm = $"{framework}-android";
+ // Remove conditional TargetFrameworks lines (iOS/macOS/Windows additions)
+ content = Regex.Replace(content,
+ @"\s*[^<]*",
+ "");
+ // Set the base TargetFrameworks to Android only
+ content = Regex.Replace(content,
+ @"[^<]*",
+ $"{androidTfm}");
+ File.WriteAllText(projectFile, content);
+ }
+
}
}