diff --git a/Documentation/docs-mobile/TOC.yml b/Documentation/docs-mobile/TOC.yml index 3faf90e458e..b4fe476a5fd 100644 --- a/Documentation/docs-mobile/TOC.yml +++ b/Documentation/docs-mobile/TOC.yml @@ -272,6 +272,8 @@ href: messages/xa1048.md - name: XA1049 href: messages/xa1049.md + - name: XA1050 + href: messages/xa1050.md - name: "XA2xxx: Linker" items: - name: "XA2xxx: Linker" diff --git a/Documentation/docs-mobile/messages/index.md b/Documentation/docs-mobile/messages/index.md index 88e7609ec63..abe2d010109 100644 --- a/Documentation/docs-mobile/messages/index.md +++ b/Documentation/docs-mobile/messages/index.md @@ -159,6 +159,7 @@ Either change the value in the AndroidManifest.xml to match the $(SupportedOSPla + [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'. ++ [XA1050](xa1050.md): The 'AndroidR8ObfuscationMode' MSBuild property has an invalid value. ## XA2xxx: Linker diff --git a/Documentation/docs-mobile/messages/xa1050.md b/Documentation/docs-mobile/messages/xa1050.md new file mode 100644 index 00000000000..1f984daa7ba --- /dev/null +++ b/Documentation/docs-mobile/messages/xa1050.md @@ -0,0 +1,34 @@ +--- +title: .NET for Android error XA1050 +description: XA1050 error code +ms.date: 09/10/2026 +f1_keywords: + - "XA1050" +--- + +# .NET for Android error XA1050 + +## Example messages + +```dotnetcli +error XA1050: The 'AndroidR8ObfuscationMode' MSBuild property has an invalid value of 'private-member'. Valid values are 'disabled' and 'private-members'. +``` + +## Issue + +The [`$(AndroidR8ObfuscationMode)`](../building-apps/build-properties.md#androidr8obfuscationmode) +MSBuild property contains an unsupported value. This property is validated when +R8 runs. + +## Solution + +Set `$(AndroidR8ObfuscationMode)` to one of the supported values: + +```xml + + private-members + +``` + +Use `disabled` to preserve all Java names and use the legacy non-optimizing +Android R8 configuration. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs index c813ec95a02..13986a46813 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs @@ -1024,6 +1024,15 @@ public static string XA1049 { return ResourceManager.GetString("XA1049", resourceCulture); } } + + /// + /// Looks up a localized string similar to The 'AndroidR8ObfuscationMode' MSBuild property has an invalid value of '{0}'. Valid values are 'disabled' and 'private-members'.. + /// + public static string XA1050 { + get { + return ResourceManager.GetString("XA1050", resourceCulture); + } + } /// /// Looks up a localized string similar to Use of AppDomain.CreateDomain() detected in assembly: {0}. .NET 6 and higher will only support a single AppDomain, so this API will no longer be available in .NET for Android once .NET 6 is released.. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index daf6297d574..c85742d1345 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -1149,6 +1149,11 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS The 'AndroidEnableMarshalMethods' and 'PublishReadyToRun' MSBuild properties cannot both be set to 'true'. Set one property to 'false'. The following are literal names and should not be translated: AndroidEnableMarshalMethods, PublishReadyToRun, MSBuild, true, false. + + The 'AndroidR8ObfuscationMode' MSBuild property has an invalid value of '{0}'. Valid values are 'disabled' and 'private-members'. + The following are literal names and should not be translated: AndroidR8ObfuscationMode, MSBuild, disabled, private-members. +{0} - The invalid value of the AndroidR8ObfuscationMode MSBuild property. + Java dependency '{0}' is not satisfied. The following are literal names and should not be translated: Java. diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs index f16643f4ba3..c93ff852fb4 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs @@ -62,6 +62,27 @@ public void CheckR8MetadataFilesExist ( } } + [TestCase ("", true)] + [TestCase ("r8", false)] + public void InvalidR8ObfuscationModeIsValidatedOnlyForR8 (string linkTool, bool expectedResult) + { + var proj = new XamarinAndroidApplicationProject { + IsRelease = true, + }; + proj.SetProperty (proj.ReleaseProperties, KnownProperties.AndroidLinkTool, linkTool); + proj.SetProperty (proj.ReleaseProperties, KnownProperties.AndroidR8ObfuscationMode, "private-member"); + + using var builder = CreateApkBuilder (); + builder.Target = "_ValidateAndroidR8ObfuscationMode"; + builder.ThrowOnBuildFailure = false; + builder.AutomaticNuGetRestore = false; + Assert.AreEqual (expectedResult, builder.Build (proj), "Validation result should depend on whether R8 is enabled."); + if (!expectedResult) { + StringAssertEx.Contains ("error XA1050", builder.LastBuildOutput); + StringAssertEx.Contains ("'private-member'", builder.LastBuildOutput); + } + } + [Test] public void CheckR8InfoMessagesToNotBreakTheBuild ([Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime) { diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 711bfc8d1ba..2feb9d14bbf 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -3078,6 +3078,15 @@ because xbuild doesn't support framework reference assemblies. Condition=" '$(AndroidApplication)' == 'True' "/> + + + +