Skip to content
Merged
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
2 changes: 2 additions & 0 deletions Documentation/docs-mobile/TOC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@
href: messages/xa1043.md
- name: XA1048
href: messages/xa1048.md
- name: XA1049
href: messages/xa1049.md
- name: "XA2xxx: Linker"
items:
- name: "XA2xxx: Linker"
Expand Down
3 changes: 3 additions & 0 deletions Documentation/docs-mobile/building-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ for Java `native` method registration.

This property is False by default.

This property cannot be set to `true` when
[`$(PublishReadyToRun)`](#publishreadytorun) is `true`.

Added in .NET 8.

## AndroidEnableMultiDex
Expand Down
1 change: 1 addition & 0 deletions Documentation/docs-mobile/messages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Either change the value in the AndroidManifest.xml to match the $(SupportedOSPla
+ [XA1046](xa1046.md): Attribute '{0}' in element '{1}' has value '{2}' that cannot be parsed as boolean; {3} line {4}.
+ [XA1047](xa1047.md): Required attribute '{0}' missing from element '{1}'; {2} line {3}.
+ [XA1048](xa1048.md): '{0}' does not contain an <instrumentation> element.
+ [XA1049](xa1049.md): The 'AndroidEnableMarshalMethods' and 'PublishReadyToRun' MSBuild properties cannot both be set to 'true'.

## XA2xxx: Linker

Expand Down
41 changes: 41 additions & 0 deletions Documentation/docs-mobile/messages/xa1049.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: .NET for Android error XA1049
description: XA1049 error code
ms.date: 08/31/2026
f1_keywords:
- "XA1049"
---

# .NET for Android error XA1049

## Example messages

```dotnetcli
error XA1049: The 'AndroidEnableMarshalMethods' and 'PublishReadyToRun' MSBuild properties cannot both be set to 'true'. Set one property to 'false'.
```

## Issue

[`$(AndroidEnableMarshalMethods)`](../building-apps/build-properties.md#androidenablemarshalmethods)
rewrites managed assemblies after trimming, while
[`$(PublishReadyToRun)`](../building-apps/build-properties.md#publishreadytorun)
adds native code to those assemblies. The marshal methods rewriter cannot modify
ReadyToRun assemblies.

## Solution

Disable marshal methods or ReadyToRun in the project file:

```xml
<PropertyGroup>
<AndroidEnableMarshalMethods>false</AndroidEnableMarshalMethods>
</PropertyGroup>
```

Alternatively:

```xml
<PropertyGroup>
<PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup>
```

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

4 changes: 4 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,10 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS
{0} - The path to the AndroidManifest.xml file.
</comment>
</data>
<data name="XA1049" xml:space="preserve">
<value>The 'AndroidEnableMarshalMethods' and 'PublishReadyToRun' MSBuild properties cannot both be set to 'true'. Set one property to 'false'.</value>
<comment>The following are literal names and should not be translated: AndroidEnableMarshalMethods, PublishReadyToRun, MSBuild, true, false.</comment>
</data>
<data name="XA4241" xml:space="preserve">
<value>Java dependency '{0}' is not satisfied.</value>
<comment>The following are literal names and should not be translated: Java.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ public void BasicApplicationPublishReadyToRun ([Values] bool isComposite, [Value
StringAssert.Contains ("@uncompressed_assemblies_data_buffer = dso_local local_unnamed_addr global [0 x i8] zeroinitializer, align 1", compressedAssembliesSourceText);
}

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

using var b = CreateApkBuilder ();
b.ThrowOnBuildFailure = false;
Assert.IsFalse (b.Build (proj), "Build should have failed.");
StringAssertEx.Contains ("error XA1049", b.LastBuildOutput);
StringAssertEx.Contains ("AndroidEnableMarshalMethods", b.LastBuildOutput);
StringAssertEx.Contains ("PublishReadyToRun", b.LastBuildOutput);
StringAssertEx.DoesNotContain ("XARMM7015", b.LastBuildOutput, "Build should fail before rewriting ReadyToRun assemblies.");
}

[Test]
public void BasicApplicationPublishReadyToRunCustomConfiguration ([Values] bool isComposite, [Values ("android-x64", "android-arm64")] string rid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,10 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
ResourceName="XA0119_ReadyToRunWithoutTrimming"
Condition=" '$(_AndroidReadyToRunWithoutTrimming)' == 'true' "
/>
<AndroidError Code="XA1049"
ResourceName="XA1049"
Condition=" '$(AndroidEnableMarshalMethods)' == 'True' And '$(PublishReadyToRun)' == 'True' "
/>
<AndroidWarning Code="XA1027"
ResourceName="XA1027"
Condition=" $(_AndroidXA1027) == 'true' "
Expand Down
Loading