Skip to content

Commit 77ac82a

Browse files
[release/8.0.1xx] [Xamarin.Android.Build.Tasks] XA1039 warning for Android.Support (#8648)
Context: 2f19238 Commit 2f19238 introduces a new XA1039 error when the Android Support libraries are referenced by a .NET 9 project. For .NET 8, partially backport 2f19238 to emit an XA1039 *warning* when the Android Support libraries are referenced by a .NET 8 project. Also introduce a new `$(_AndroidIgnoreAndroidSupportWarning)` MSBuild property as an escape hatch if someone needs to completely disable the warning: <_AndroidIgnoreAndroidSupportWarning>true</_AndroidIgnoreAndroidSupportWarning> .NET 9 will not honor or support `$(_AndroidIgnoreAndroidSupportWarning)`.
1 parent c22c17f commit 77ac82a

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Xamarin.Android warning XA1039
3+
description: XA1039 warning code
4+
ms.date: 1/10/2024
5+
---
6+
# Xamarin.Android warning XA1039
7+
8+
## Example messages
9+
10+
```
11+
warning XA1039: The Android Support libraries are not supported in .NET 9 and later, please migrate to AndroidX. See https://aka.ms/xamarin/androidx for more details.
12+
```
13+
14+
## Issue
15+
16+
Outdated "Android Support Library" packages are no longer supported in .NET 9:
17+
18+
* `Xamarin.Android.Arch.*`
19+
* `Xamarin.Android.Support.*`
20+
21+
The underlying Java libraries are no longer supported by Google since the final
22+
28.0.0 release. See the [Android Support Library Documentation][support] for
23+
details.
24+
25+
Some example prefixes of the newer, supported AndroidX packages are:
26+
27+
* `Xamarin.AndroidX.*`
28+
* `Xamarin.AndroidX.Arch.*`
29+
30+
For more information about the Android Support libraries or AndroidX, see:
31+
32+
* [Android Support Library Documentation][support]
33+
* [AndroidX Documentation](https://developer.android.com/jetpack/androidx)
34+
35+
[support]: https://developer.android.com/topic/libraries/support-library/packages
36+
37+
## Solution
38+
39+
Remove all NuGet package references to `Xamarin.Android.Support` or
40+
`Xamarin.Android.Arch` in favor of the new AndroidX equivalents.
41+
42+
This also can occur if you are using a NuGet package with a transitive
43+
dependency on the Android support packages. In this case, you will need to
44+
remove the package or contact the package author.
45+
46+
See the [AndroidX migration documentation](https://aka.ms/xamarin/androidx) for
47+
details.

src/Xamarin.Android.Build.Tasks/Properties/Resources.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,4 +947,8 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS
947947
{0} - An Android Resource Identifier.
948948
</comment>
949949
</data>
950+
<data name="XA1039" xml:space="preserve">
951+
<value>The Android Support libraries are not supported in .NET 9 and later, please migrate to AndroidX. See https://aka.ms/xamarin/androidx for more details.</value>
952+
<comment>The following are literal names and should not be translated: Android Support, AndroidX, .NET.</comment>
953+
</data>
950954
</root>

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,19 @@ public void XA4310 ([Values ("apk", "aab")] string packageFormat)
14631463
}
14641464
}
14651465

1466+
[Test]
1467+
public void XA1039 ()
1468+
{
1469+
var proj = new XamarinAndroidApplicationProject {
1470+
PackageReferences = {
1471+
KnownPackages.SupportCompat_27_0_2_1
1472+
}
1473+
};
1474+
using var builder = CreateApkBuilder ();
1475+
Assert.IsTrue (builder.Build (proj), "build should have succeeded");
1476+
StringAssertEx.Contains ("warning XA1039", builder.LastBuildOutput, "Should get XA1039 warning");
1477+
}
1478+
14661479
[Test]
14671480
[NonParallelizable]
14681481
public void CheckLintErrorsAndWarnings ()

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,23 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
499499
/>
500500
</Target>
501501

502+
<Target Name="_CheckUnsupportedPackages"
503+
Condition=" '$(_AndroidIgnoreAndroidSupportWarning)' != 'true' "
504+
AfterTargets="ResolvePackageAssets">
505+
<ItemGroup>
506+
<_AndroidUnsupportedPackages
507+
Include="%(ResolvedCompileFileDefinitions.NuGetPackageId)"
508+
Condition=" '%(ResolvedCompileFileDefinitions.NuGetPackageId)' != '' and
509+
( $([System.String]::Copy(%(ResolvedCompileFileDefinitions.NuGetPackageId)).StartsWith ('Xamarin.Android.Arch.')) or
510+
$([System.String]::Copy(%(ResolvedCompileFileDefinitions.NuGetPackageId)).StartsWith ('Xamarin.Android.Support.')) )"
511+
/>
512+
</ItemGroup>
513+
<AndroidWarning Code="XA1039"
514+
ResourceName="XA1039"
515+
Condition=" '@(_AndroidUnsupportedPackages->Count())' != '0' "
516+
/>
517+
</Target>
518+
502519
<Target Name="_CheckNonIdealConfigurations">
503520
<AndroidWarning Code="XA0119"
504521
ResourceName="XA0119_AOT"

0 commit comments

Comments
 (0)