Skip to content

Commit 0db0be1

Browse files
[xabt] don't set $(UseMonoRuntime) by default (#10527)
This makes CoreCLR the default runtime. Fixes or (temporarily) disables a number of tests which were failing because of a variety of reasons, such as: - Use of 32-bit ABIs (CoreCLR supports only 64-bit ones) - MonoAOT use (not supported by CoreCLR) - Using discrete assemblies in the apk instead of assembly stores (CoreCLR supports only the latter) - Mono.Cecil lack of support for R2R assembly images. - A handful of typemap tests (CoreCLR managed typemap support is buggy, another solution is being worked on) Additionally, it parametrizes a number of tests with the runtime type, so that they ran for both MonoVM and CoreCLR (and, eventually, NativeAOT) Co-authored-by: Marek Habersack <grendel@twistedcode.net>
1 parent 3ba7201 commit 0db0be1

39 files changed

+3527
-327
lines changed

Documentation/docs-mobile/messages/xa1040.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@ ms.date: 02/24/2025
88
## Example messages
99

1010
```
11-
warning XA1040: The CoreCLR runtime on Android is an experimental feature and not yet suitable for production use. File issues at: https://github.com/dotnet/android/issues
1211
warning XA1040: The NativeAOT runtime on Android is an experimental feature and not yet suitable for production use. File issues at: https://github.com/dotnet/android/issues
1312
```
1413

1514
## Issue
1615

17-
MonoVM is the default, supported runtime for .NET for Android.
16+
CoreCLR is the default, supported runtime for .NET for Android. Mono is also supported.
1817

19-
Other runtimes are currently experimental, such as:
18+
You can opt into other runtimes via:
2019

21-
* CoreCLR, used via `$(UseMonoRuntime)=false`
20+
* CoreCLR, default
21+
* MonoVM, used via `$(UseMonoRuntime)=true`
2222
* NativeAOT, used via `$(PublishAot)=true`
2323

2424
## Solution
2525

2626
To silence this warning, you can either:
2727

28-
* Use MonoVM by removing `$(UseMonoRuntime)=false` or
29-
`$(PublishAot)=true` from your project file.
28+
* Use CoreCLR by removing `$(PublishAot)=true` from your project file.
3029

3130
* Set `$(EnablePreviewFeatures)` to `true` in your project file.

build-tools/automation/yaml-templates/stage-package-tests.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ stages:
8686
testName: Mono.Android.NET_Tests-Interpreter
8787
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
8888
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)Interpreter.xml
89-
extraBuildArgs: -p:TestsFlavor=Interpreter -p:UseInterpreter=True
89+
extraBuildArgs: -p:TestsFlavor=Interpreter -p:UseInterpreter=True -p:UseMonoRuntime=true
9090
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab
9191
artifactFolder: $(DotNetTargetFramework)-Interpreter
9292

@@ -154,7 +154,7 @@ stages:
154154
testName: Mono.Android.NET_Tests-NoAot
155155
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
156156
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)NoAot.xml
157-
extraBuildArgs: -p:TestsFlavor=NoAot -p:RunAOTCompilation=false
157+
extraBuildArgs: -p:TestsFlavor=NoAot -p:RunAOTCompilation=false -p:UseMonoRuntime=true
158158
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab
159159
artifactFolder: $(DotNetTargetFramework)-NoAot
160160

@@ -164,7 +164,7 @@ stages:
164164
testName: Mono.Android.NET_Tests-TrimModePartial
165165
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
166166
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)TrimModePartial.xml
167-
extraBuildArgs: -p:TestsFlavor=TrimModePartial -p:TrimMode=partial
167+
extraBuildArgs: -p:TestsFlavor=TrimModePartial -p:TrimMode=partial -p:UseMonoRuntime=true
168168
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab
169169
artifactFolder: $(DotNetTargetFramework)-TrimModePartial
170170

@@ -174,7 +174,7 @@ stages:
174174
testName: Mono.Android.NET_Tests-AotLlvm
175175
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
176176
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)AotLlvm.xml
177-
extraBuildArgs: -p:TestsFlavor=AotLlvm -p:EnableLLVM=true -p:AndroidEnableProfiledAot=false
177+
extraBuildArgs: -p:TestsFlavor=AotLlvm -p:EnableLLVM=true -p:AndroidEnableProfiledAot=false -p:UseMonoRuntime=true
178178
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab
179179
artifactFolder: $(DotNetTargetFramework)-AotLlvm
180180

@@ -184,7 +184,7 @@ stages:
184184
testName: Mono.Android.NET_Tests-IsAssignableFrom
185185
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
186186
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)IsAssignableFrom.xml
187-
extraBuildArgs: -p:TestsFlavor=IsAssignableFrom -p:IncludeCategories=Intune -p:_AndroidIsAssignableFromCheck=false
187+
extraBuildArgs: -p:TestsFlavor=IsAssignableFrom -p:IncludeCategories=Intune -p:_AndroidIsAssignableFromCheck=false -p:UseMonoRuntime=true
188188
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab
189189
artifactFolder: $(DotNetTargetFramework)-IsAssignableFrom
190190

build-tools/scripts/TestApks.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<PropertyGroup>
2020
<!-- APK tests might run on 32-bit emulators -->
21-
<RuntimeIdentifiers Condition=" '$(RuntimeIdentifier)' == '' and '$(PublishAot)' != 'true' and '$(UseMonoRuntime)' != 'false' ">android-arm64;android-x86;android-x64;</RuntimeIdentifiers>
21+
<RuntimeIdentifiers Condition=" '$(RuntimeIdentifier)' == '' and '$(PublishAot)' != 'true' and '$(UseMonoRuntime)' == 'true' ">android-arm64;android-x86;android-x64;</RuntimeIdentifiers>
2222
<TestAvdApiLevel Condition=" '$(TestAvdApiLevel)' == '' ">29</TestAvdApiLevel>
2323
<TestAvdAbi Condition=" '$(TestAvdAbi)' == '' and '$(HostOS)' == 'Darwin' and '$(HostOSArchitecture)' == 'Arm64' ">arm64-v8a</TestAvdAbi>
2424
<TestAvdAbi Condition=" '$(TestAvdAbi)' == '' ">x86_64</TestAvdAbi>

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
See: https://github.com/dotnet/sdk/blob/955c0fc7b06e2fa34bacd076ed39f61e4fb61716/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L16
2323
-->
2424
<_GetChildProjectCopyToPublishDirectoryItems>false</_GetChildProjectCopyToPublishDirectoryItems>
25-
<UseMonoRuntime Condition=" '$(PublishAot)' == 'true' and '$(UseMonoRuntime)' == '' ">false</UseMonoRuntime>
26-
<UseMonoRuntime Condition=" '$(UseMonoRuntime)' == '' ">true</UseMonoRuntime>
27-
<_AndroidRuntime Condition=" '$(PublishAot)' == 'true' and '$(UseMonoRuntime)' != 'true' ">NativeAOT</_AndroidRuntime>
28-
<_AndroidRuntime Condition=" '$(PublishAot)' != 'true' and '$(UseMonoRuntime)' != 'true' ">CoreCLR</_AndroidRuntime>
29-
<_AndroidRuntime Condition=" '$(_AndroidRuntime)' == '' ">MonoVM</_AndroidRuntime>
25+
<_AndroidRuntime Condition=" '$(PublishAot)' == 'true' ">NativeAOT</_AndroidRuntime>
26+
<_AndroidRuntime Condition=" '$(PublishAot)' != 'true' and '$(UseMonoRuntime)' == 'true' ">MonoVM</_AndroidRuntime>
27+
<_AndroidRuntime Condition=" '$(_AndroidRuntime)' == '' ">CoreCLR</_AndroidRuntime>
3028
<PublishAotUsingRuntimePack Condition=" '$(PublishAotUsingRuntimePack)' == '' and '$(_AndroidRuntime)' == 'NativeAOT' ">true</PublishAotUsingRuntimePack>
3129

3230
<!-- Use $(AndroidMinimumSupportedApiLevel) for $(SupportedOSPlatformVersion) if unset -->

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public void BuildBasicApplicationReleaseProfiledAot ([Values (true, false)] bool
6969
IsRelease = true,
7070
AndroidEnableProfiledAot = true,
7171
};
72+
// Mono-only test
73+
proj.SetRuntime (AndroidRuntime.MonoVM);
7274
proj.SetProperty ("EnableLLVM", enableLLVM.ToString ());
7375
proj.SetProperty (proj.ActiveConfigurationProperties, "AndroidExtraAotOptions", "--verbose");
7476
using var b = CreateApkBuilder ();
@@ -84,6 +86,8 @@ public void BuildBasicApplicationReleaseWithCustomAotProfile ()
8486
IsRelease = true,
8587
AndroidEnableProfiledAot = true,
8688
};
89+
// A Mono-only test
90+
proj.SetRuntime (AndroidRuntime.MonoVM);
8791
proj.SetProperty (proj.ActiveConfigurationProperties, "AndroidExtraAotOptions", "--verbose");
8892

8993
byte [] custom_aot_profile = XamarinAndroidCommonProject.GetResourceContents ("Xamarin.ProjectTools.Resources.Base.custom.aotprofile");
@@ -102,32 +106,60 @@ public void BuildBasicApplicationReleaseProfiledAotWithoutDefaultProfile ()
102106
IsRelease = true,
103107
AndroidEnableProfiledAot = true,
104108
};
109+
// Mono-only test
110+
proj.SetRuntime (AndroidRuntime.MonoVM);
105111
proj.SetProperty (proj.ActiveConfigurationProperties, "AndroidUseDefaultAotProfile", "false");
106112
using var b = CreateApkBuilder ();
107113
b.Verbosity = LoggerVerbosity.Detailed;
108114
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
109115
StringAssertEx.DoesNotContainRegex (@$"Using profile data file.*dotnet\.aotprofile", b.LastBuildOutput, "Should not use default AOT profile", RegexOptions.IgnoreCase);
110116
}
111117

118+
static IEnumerable<object[]> Get_BuildAotApplicationWithSpecialCharactersInProjectData ()
119+
{
120+
var ret = new List<object[]> ();
121+
122+
foreach (AndroidRuntime runtime in new[] { AndroidRuntime.MonoVM, AndroidRuntime.CoreCLR }) {
123+
AddTestData ("テスト", false, false, runtime);
124+
AddTestData ("テスト", true, true, runtime);
125+
AddTestData ("テスト", true, false, runtime);
126+
AddTestData ("随机生成器", false, false, runtime);
127+
AddTestData ("随机生成器", true, true, runtime);
128+
AddTestData ("随机生成器", true, false, runtime);
129+
AddTestData ("中国", false, false, runtime);
130+
AddTestData ("中国", true, true, runtime);
131+
AddTestData ("中国", true, false, runtime);
132+
}
133+
134+
return ret;
135+
136+
void AddTestData (string testName, bool isRelease, bool aot, AndroidRuntime runtime)
137+
{
138+
ret.Add (new object[] {
139+
testName,
140+
isRelease,
141+
aot,
142+
runtime,
143+
});
144+
}
145+
}
146+
112147
[Test]
113-
[TestCase ("テスト", false, false)]
114-
[TestCase ("テスト", true, true)]
115-
[TestCase ("テスト", true, false)]
116-
[TestCase ("随机生成器", false, false)]
117-
[TestCase ("随机生成器", true, true)]
118-
[TestCase ("随机生成器", true, false)]
119-
[TestCase ("中国", false, false)]
120-
[TestCase ("中国", true, true)]
121-
[TestCase ("中国", true, false)]
122-
public void BuildAotApplicationWithSpecialCharactersInProject (string testName, bool isRelease, bool aot)
148+
[TestCaseSource (nameof (Get_BuildAotApplicationWithSpecialCharactersInProjectData))]
149+
public void BuildAotApplicationWithSpecialCharactersInProject (string testName, bool isRelease, bool aot, AndroidRuntime runtime)
123150
{
151+
if (aot && runtime == AndroidRuntime.CoreCLR) {
152+
Assert.Ignore ("AOT + CoreCLR == NativeAOT; Not supported yet here");
153+
return;
154+
}
155+
124156
var rootPath = Path.Combine (Root, "temp", TestName);
125157
var proj = new XamarinAndroidApplicationProject () {
126158
ProjectName = testName,
127159
IsRelease = isRelease,
128160
AotAssemblies = aot,
129161
};
130-
proj.SetAndroidSupportedAbis ("armeabi-v7a", "arm64-v8a", "x86", "x86_64");
162+
proj.SetRuntime (runtime);
131163
using (var builder = CreateApkBuilder (Path.Combine (rootPath, proj.ProjectName))){
132164
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
133165
}
@@ -156,6 +188,7 @@ public void BuildAotApplicationWithSpecialCharactersInProject (string testName,
156188
},
157189
};
158190

191+
// TODO: possibly enable NativeAOT
159192
[Test]
160193
[TestCaseSource (nameof (AotChecks))]
161194
public void BuildAotApplicationWithNdkAndBundleAndÜmläüts (string supportedAbis, bool enableLLVM, bool usesAssemblyBlobs)
@@ -171,6 +204,8 @@ public void BuildAotApplicationWithNdkAndBundleAndÜmläüts (string supportedAb
171204
PackageName = "com.xamarin.buildaotappwithspecialchars",
172205
};
173206

207+
// Mono-only test
208+
proj.SetRuntime (AndroidRuntime.MonoVM);
174209
proj.SetProperty ("AndroidNdkDirectory", AndroidNdkPath);
175210
proj.SetRuntimeIdentifiers (supportedAbis.Split (';'));
176211
proj.SetProperty ("EnableLLVM", enableLLVM.ToString ());
@@ -227,6 +262,9 @@ public void BuildAotApplicationAndÜmläüts (string supportedAbis, bool enableL
227262
AotAssemblies = true,
228263
PackageName = "com.xamarin.buildaotappandbundlewithspecialchars",
229264
};
265+
266+
// Mono-only test
267+
proj.SetRuntime (AndroidRuntime.MonoVM);
230268
proj.SetRuntimeIdentifiers (supportedAbis.Split (';'));
231269
proj.SetProperty ("EnableLLVM", enableLLVM.ToString ());
232270
proj.SetProperty ("AndroidUseAssemblyStore", usesAssemblyBlobs.ToString ());
@@ -353,6 +391,10 @@ public void NoSymbolsArgShouldReduceAppSize ([Values (false, true)] bool skipDeb
353391
IsRelease = true,
354392
AotAssemblies = true,
355393
};
394+
395+
// Mono-only test
396+
proj.SetRuntime (AndroidRuntime.MonoVM);
397+
356398
var supportedAbi = "arm64-v8a";
357399
proj.SetAndroidSupportedAbis (supportedAbi);
358400
proj.SetProperty ("EnableLLVM", true.ToString ());
@@ -393,6 +435,8 @@ public void AotAssembliesInIDE ()
393435
IsRelease = true,
394436
AotAssemblies = true,
395437
};
438+
// Mono-only test
439+
proj.SetRuntime (AndroidRuntime.MonoVM);
396440
proj.SetAndroidSupportedAbis (supportedAbis);
397441
using var b = CreateApkBuilder ();
398442
Assert.IsTrue (b.RunTarget (proj, target: "Build"));
@@ -423,6 +467,8 @@ public void CheckWhetherLibcAndLibmAreReferencedInAOTLibraries ()
423467
EmbedAssembliesIntoApk = true,
424468
AotAssemblies = true,
425469
};
470+
// Mono-only test
471+
proj.SetRuntime (AndroidRuntime.MonoVM);
426472
proj.SetProperty ("EnableLLVM", "True");
427473

428474
var abis = new [] { "arm64-v8a", "x86_64" };

0 commit comments

Comments
 (0)