Make CoreCLR the default runtime for Debug builds#11169
Conversation
There was a problem hiding this comment.
Pull request overview
This PR changes the .NET for Android SDK defaults so Debug builds no longer force UseMonoRuntime=true, which makes CoreCLR the default runtime for both Debug and Release builds (unless a project explicitly opts into MonoVM or NativeAOT).
Changes:
- Remove the Debug-only default
UseMonoRuntime=truein SDK default properties. - As a result,
_AndroidRuntimefalls back toCoreCLRwhenPublishAotis not enabled andUseMonoRuntimeisn’t explicitly set.
MSTest's VSTest bridge resolves test assembly paths via Assembly.Location, which returns empty string on CoreCLR Android with fast-deploy (assemblies are memory-mapped). This causes MSTestDiscovererHelpers.AreValidSources() to fail with NotSupportedException. Setting EmbedAssembliesIntoApk=true ensures assemblies are embedded in the APK so Assembly.Location returns a valid path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Root Cause Analysis:
|
…allback trimming (#11168) ## Summary Fixes a bug in the trimmable typemap UCO (UnmanagedCallersOnly) wrapper generator where the callback member reference used `byte` (uint8) for JNI boolean returns, but MCW-generated `n_*` callback methods use `sbyte` (int8). ## The Bug In ECMA-335 metadata, `int8` and `uint8` are different types for method signature matching. When ILLink performed its reachability analysis, it could not resolve the cross-assembly member reference from the typemap DLL to `n_*` methods in `Mono.Android.dll` because the return type did not match. ILLink then treated these `n_*` callbacks as unreachable and trimmed them. At runtime, this caused `MissingMethodException` for methods like `IHostnameVerifierInvoker.n_Verify_Ljava_lang_String_Ljavax_net_ssl_SSLSession_`, which cascaded into a SIGSEGV on a background thread. ## The Fix - Added `EncodeClrTypeForCallback()` to `JniSignatureHelper` that uses `sbyte` for JNI boolean, matching the MCW `_JniMarshal_*_B` delegate convention. - Updated `EmitUcoMethod()` in `TypeMapAssemblyEmitter` to use the callback-specific encoding when constructing the member reference to `n_*` methods. - The UCO wrapper's own method signature continues to use `byte` (correct for JNI ABI / `[UnmanagedCallersOnly]`).
Pass UseMonoRuntime=true/false via build parameters to toggle runtime. For CoreCLR, also pass EmbedAssembliesIntoApk=true as a workaround for MSTest's Assembly.Location requirement with fast-deploy. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit 7d615b0.
DotNetCLI.Build() adds /p: via GetDefaultCommandLineArgs, but StartRun() passes parameters raw. Without /p:, dotnet run receives bare 'UseMonoRuntime=True' which breaks the command. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| bool useMonoRuntime = runtime == AndroidRuntime.MonoVM; | ||
| var buildParameters = new List<string> { | ||
| $"UseMonoRuntime={useMonoRuntime}", | ||
| }; | ||
| if (runtime == AndroidRuntime.CoreCLR) { | ||
| // TODO: MSTest requires Assembly.Location, which returns empty with fast-deploy on CoreCLR. Remove when fast-deploy is fixed. | ||
| buildParameters.Add ("EmbedAssembliesIntoApk=true"); | ||
| } |
There was a problem hiding this comment.
Hmm:
- https://github.com/microsoft/testfx/blob/cba28646c410afb47d076af71c78521827a878c5/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/SynchronizedSingleSessionVSTestAndTestAnywhereAdapter.cs#L152-L154
- https://github.com/microsoft/testfx/blob/cba28646c410afb47d076af71c78521827a878c5/src/Adapter/MSTestAdapter.PlatformServices/Helpers/MSTestDiscovererHelpers.cs#L13-L28
There was a problem hiding this comment.
There was a problem hiding this comment.
the PR that will fix this looks solid: microsoft/testfx#7772
MSTest's VSTest bridge uses Assembly.Location to resolve test sources, which returns empty on CoreCLR Android. Assert.Ignore with link to tracking issue. See #11174 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jonathanpeppers
left a comment
There was a problem hiding this comment.
I ignored the one test for now, if everything looks green, feel free to merge.

This PR will switch the default runtime in .NET 11 P4 to CoreCLR. Both Release and Debug will now use CoreCLR.
Related to dotnet/macios#25050