Guard Mono-specific AOT targets for CoreCLR runtime, add XA1042 warning#11070
Guard Mono-specific AOT targets for CoreCLR runtime, add XA1042 warning#11070
Conversation
…r Mono-specific properties used with non-MonoVM runtimes Agent-Logs-Url: https://github.com/dotnet/android/sessions/a5ac81b3-0cd5-4a8a-9394-531fa1466274 Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
|
@copilot we need to fix this test: When We may want to add an additional test so this is clearer. |
There was a problem hiding this comment.
Pull request overview
This PR prevents Mono AOT build logic from running when a project is configured for non-Mono runtimes (CoreCLR/NativeAOT), and adds a dedicated warning (XA1042) to guide users who have Mono-only AOT properties set unconditionally (e.g., via Directory.Build.props).
Changes:
- Guard MonoAOTCompiler SDK imports and
_AndroidAotexecution so they only run forMonoVM. - Detect
RunAOTCompilation/EnableLLVMset under non-Mono runtimes, reset them tofalse, and emit XA1042 with actionable guidance. - Add XA1042 resource + documentation and add tests validating warning emission and successful builds under CoreCLR.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets | Restricts MonoAOTCompiler SDK imports and _AndroidAot target to MonoVM runtime only. |
| src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets | Detects Mono-only properties under non-Mono runtimes, sets XA1042 flags, and resets the properties to false. |
| src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets | Emits XA1042 warnings when the corresponding flags are set. |
| src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | Adds localized XA1042 warning message template. |
| src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs | Regenerates strongly-typed resource accessor for XA1042. |
| Documentation/docs-mobile/messages/xa1042.md | Adds end-user documentation and migration guidance for XA1042. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs | Adds tests ensuring CoreCLR builds succeed and XA1042 is emitted when Mono-only properties are set. |
Files not reviewed (1)
- src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Language not supported
…ated test Agent-Logs-Url: https://github.com/dotnet/android/sessions/1e564b95-24aa-400d-b01f-f153bea868fd Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
... Fixed in b2456ac. The issue was that my XA1042 change resets Two changes:
|
The CalculateProjectDependencies task was emitting 'ndk-bundle' as the
AndroidDependency item identity, but modern Android SDK uses side-by-side
NDK installed under 'ndk/{version}'. The GoogleV2 manifest doesn't have
a component with path 'ndk-bundle', causing InstallAndroidDependencies
to fail with 'could not be resolved' warnings.
Change the identity to 'ndk' so it matches the GoogleV2 manifest component
and resolves correctly.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use ndk/{version} (e.g. ndk/27.2.1247901) as the AndroidDependency
identity, matching the pattern used by build-tools/{version} and
cmdline-tools/{version}. This allows the GoogleV2 manifest to resolve
the NDK component correctly.
Also fix tests:
- Skip GetDependencyNdkRequiredConditions for NativeAOT when
ndkRequired=false, since NativeAOT always requires NDK via
PublishAot=true
- Update NativeAotRequiresNdk assertion from ndk-bundle to ndk/
- Use ndk/ prefix matching in StringAssertEx to avoid false positives
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The downstream InstallAndroidDependencies task (from android-platform-support)
joins the identity and version with a semicolon separator to form the SDK
manager path (e.g. ndk;27.2.12479018). Using ndk/{version} as the identity
caused a malformed path like 'ndk;27.2.12479018/27.2.12479018' that couldn't
be resolved.
The correct identity is just 'ndk' with the version in metadata, which
produces the expected 'ndk;27.2.12479018' component path.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Setting
<RunAOTCompilation>true</RunAOTCompilation>in a project file (e.g.Directory.Build.props) causes build failures when switching from Mono to CoreCLR, becauseMonoAOTCompilerruns unconditionally regardless of the active runtime.Changes
Microsoft.Android.Sdk.Aot.targets— Add'$(_AndroidRuntime)' == 'MonoVM'guard to theImportGroup(MonoAOTCompiler SDK imports) and_AndroidAottarget conditionMicrosoft.Android.Sdk.DefaultProperties.targets— AfterRunAOTCompilationdefaults are resolved, detect Mono-specific properties (RunAOTCompilation,EnableLLVM) set with non-MonoVM runtimes, reset them tofalse, and set flags for warning emissionXamarin.Android.Common.targets— Emit new XA1042 warning when the flags are set; add$(PublishAot)condition to_NdkRequiredso NativeAOT always requires the Android NDKResources.resx/Resources.Designer.cs— New XA1042 messagexa1042.md— Documentation for the new warningAotTests.cs— Two tests:RunAOTCompilationWithCoreClrWarnsAndSkipsMonoAotandEnableLLVMWithCoreClrWarnsAndIsIgnoredAndroidDependenciesTests.cs— NewNativeAotRequiresNdktest validating that NativeAOT always lists the NDK as a dependencyExample warning
Migration guidance