Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Documentation/docs-mobile/messages/xa1042.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: .NET for Android warning XA1042
description: XA1042 warning code
ms.date: 04/02/2026
f1_keywords:
- "XA1042"
---

# .NET for Android warning XA1042

## Example messages

```
warning XA1042: The MSBuild property 'RunAOTCompilation' is not compatible with the CoreCLR runtime and will be ignored. Either remove the property or guard it with a condition: Condition="'$(UseMonoRuntime)' == 'true'"
```

## Issue

This warning indicates that a Mono-specific MSBuild property is set in
the project file, but the project is configured to use a non-Mono
runtime (such as CoreCLR or NativeAOT). The property will have no
effect with the current runtime and will be ignored.

Properties that trigger this warning include:
- `RunAOTCompilation` — Mono AOT compilation; CoreCLR uses `PublishReadyToRun` instead.
- `EnableLLVM` — Enables LLVM for the Mono AOT compiler.

## Solution

Remove the Mono-specific property from your project file or
`Directory.Build.props`, or guard it with a runtime condition:

```xml
<PropertyGroup Condition=" '$(UseMonoRuntime)' == 'true' ">
<RunAOTCompilation>true</RunAOTCompilation>
</PropertyGroup>
```

For CoreCLR, use `PublishReadyToRun` instead of `RunAOTCompilation`:

```xml
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ They run in a context of an inner build with a single $(RuntimeIdentifier).
when $(MonoAOTCompilerTasksAssemblyPath) is blank:
https://github.com/dotnet/runtime/blob/69711860262e44458bbe276393ea3eb9f7a2192a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets.in#L20-L25
-->
<ImportGroup Condition=" '$(MonoAOTCompilerTasksAssemblyPath)' == '' and '$(AotAssemblies)' == 'true' ">
<ImportGroup Condition=" '$(MonoAOTCompilerTasksAssemblyPath)' == '' and '$(AotAssemblies)' == 'true' and '$(_AndroidRuntime)' == 'MonoVM' ">
<Import Project="Sdk.props" Sdk="Microsoft.NET.Runtime.MonoAOTCompiler.Task" />
<Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-x86" />
<Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-x64" />
Expand All @@ -39,7 +39,7 @@ They run in a context of an inner build with a single $(RuntimeIdentifier).
</Target>

<Target Name="_AndroidAot"
Condition=" '$(AotAssemblies)' == 'true' and '$(RuntimeIdentifier)' != '' "
Condition=" '$(AotAssemblies)' == 'true' and '$(RuntimeIdentifier)' != '' and '$(_AndroidRuntime)' == 'MonoVM' "
DependsOnTargets="_CreatePropertiesCache;_AndroidAotInputs;_AndroidAotCompilation">
<ReadLinesFromFile File="$(_AndroidStampDirectory)_AndroidAot.stamp">
<Output TaskParameter="Lines" ItemName="_AotCompiledAssemblies" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' and '$(AotAssemblies)' == '' and '$(Configuration)' == 'Release' and '$(_AndroidRuntime)' == 'MonoVM' ">true</RunAOTCompilation>
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' and '$(AotAssemblies)' == 'true' ">true</RunAOTCompilation>
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' ">false</RunAOTCompilation>
<!-- Warn and reset Mono-specific properties when the runtime is not MonoVM -->
<_AndroidXA1042_RunAOTCompilation Condition=" '$(RunAOTCompilation)' == 'true' and '$(_AndroidRuntime)' != 'MonoVM' ">true</_AndroidXA1042_RunAOTCompilation>
<_AndroidXA1042_EnableLLVM Condition=" '$(EnableLLVM)' == 'true' and '$(_AndroidRuntime)' != 'MonoVM' ">true</_AndroidXA1042_EnableLLVM>
<RunAOTCompilation Condition=" '$(_AndroidXA1042_RunAOTCompilation)' == 'true' ">false</RunAOTCompilation>
<EnableLLVM Condition=" '$(_AndroidXA1042_EnableLLVM)' == 'true' ">false</EnableLLVM>
<_AndroidXA1029 Condition=" '$(AotAssemblies)' != '' ">true</_AndroidXA1029>
<_AndroidXA1030 Condition=" '$(RunAOTCompilation)' == 'true' and '$(PublishTrimmed)' == 'false' ">true</_AndroidXA1030>
<AotAssemblies>$(RunAOTCompilation)</AotAssemblies>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,13 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS
<comment>The following are literal names and should not be translated: .NET.
{0} - The MSBuild property that has the incorrect value.
{1} - The current value of the property
</comment>
</data>
<data name="XA1042" xml:space="preserve">
<value>The MSBuild property '{0}' is not compatible with the {1} runtime and will be ignored. Either remove the property or guard it with a condition: Condition="'$(UseMonoRuntime)' == 'true'"</value>
<comment>The following are literal names and should not be translated: MSBuild, UseMonoRuntime.
{0} - The MSBuild property name (e.g. RunAOTCompilation, EnableLLVM).
{1} - The name of the .NET runtime (e.g. CoreCLR, NativeAOT).
</comment>
</data>
<data name="XA4241" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,5 +492,37 @@ public void CheckWhetherLibcAndLibmAreReferencedInAOTLibraries ()
}
}

[Test]
public void RunAOTCompilationWithCoreClrWarnsAndSkipsMonoAot ()
{
var proj = new XamarinAndroidApplicationProject {
IsRelease = true,
};
proj.SetRuntime (AndroidRuntime.CoreCLR);
proj.SetProperty ("RunAOTCompilation", "true");

using var b = CreateApkBuilder ();
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
StringAssertEx.Contains ("warning XA1042", b.LastBuildOutput, "Build output should contain warning XA1042");
StringAssertEx.Contains ("RunAOTCompilation", b.LastBuildOutput, "Build output should mention RunAOTCompilation");
StringAssertEx.Contains ("CoreCLR", b.LastBuildOutput, "Build output should mention CoreCLR");
}

[Test]
public void EnableLLVMWithCoreClrWarnsAndIsIgnored ()
{
var proj = new XamarinAndroidApplicationProject {
IsRelease = true,
};
proj.SetRuntime (AndroidRuntime.CoreCLR);
proj.SetProperty ("EnableLLVM", "true");

using var b = CreateApkBuilder ();
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
StringAssertEx.Contains ("warning XA1042", b.LastBuildOutput, "Build output should contain warning XA1042");
StringAssertEx.Contains ("EnableLLVM", b.LastBuildOutput, "Build output should mention EnableLLVM");
StringAssertEx.Contains ("CoreCLR", b.LastBuildOutput, "Build output should mention CoreCLR");
}

}
}
10 changes: 10 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,16 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
ResourceName="XA1030"
Condition=" $(_AndroidXA1030) == 'true' "
/>
<AndroidWarning Code="XA1042"
ResourceName="XA1042"
FormatArguments="RunAOTCompilation;$(_AndroidRuntime)"
Condition=" '$(_AndroidXA1042_RunAOTCompilation)' == 'true' "
/>
<AndroidWarning Code="XA1042"
ResourceName="XA1042"
FormatArguments="EnableLLVM;$(_AndroidRuntime)"
Condition=" '$(_AndroidXA1042_EnableLLVM)' == 'true' "
/>
<AndroidError Code="XA1011"
ResourceName="XA1011"
Condition=" '$(AndroidLinkTool)' == 'proguard' And '$(AndroidDexTool)' == 'd8' "
Expand Down