From 63cfce42f6ec325b8cf050a85dc1c07fa5762299 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 9 Jan 2025 00:14:08 +0000 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Add %(NuGetPackage*) to TaskItems (#9559) Fixes: https://github.com/dotnet/android/issues/9544 Context: 64bb147f2ead5bd403a823d27b33f590197477fa [Google announced][0] that future versions of Android would require that native libraries use 16 KB page sizes on arm64. At present, the timeline for *when* 16 KB page sizes will be required is unknown, though we assume it will be with Android 16 or later. In order to get ahead of this, .NET 9 added an XA0141 warning in 64bb147f. The problem is, this warning is not entirely actionable: dotnet new android dotnet add package Xamarin.GooglePlayServices.Vision.Face.Contour.Internal --version 116.1.0.19 dotnet build -c Release results in: warning XA0141: NuGet package '' version '' contains a shared library 'libface_detector_v2_jni.so' which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details warning XA0141: NuGet package '' version '' contains a shared library 'libface_detector_v2_jni.so' which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details What are customers supposed to *do* with this? The original assumption was that the NuGet package and Version would be available as metadata items on the MSBuild Items. Unfortunately that was not the case, so the data the user gets is empty. Add the required metadata to all NuGet Package references resolved by the project. This will allow us to propagate that data throughout the build Items as they are transformed. This means we can provide a decent error message to the user: warning XA0141: Android 16 will require 16 KB page sizes, shared library 'libface_detector_v2_jni.so' does not have a 16 KB page size. Please inform the authors of the NuGet package 'Xamarin.GooglePlayServices.Vision.Face.Contour.Internal' version '116.1.0.19' which contains 'lib/net8.0-android34.0/play-services-vision-face-contour-internal.aar'. See https://developer.android.com/guide/practices/page-sizes for more details. [0]: https://android-developers.googleblog.com/2024/08/adding-16-kb-page-size-to-android.html --- Documentation/docs-mobile/messages/xa0141.md | 20 ++- ...osoft.Android.Sdk.AndroidLibraries.targets | 2 +- .../Properties/Resources.resx | 5 +- .../Tasks/GetImportedLibraries.cs | 55 +++++--- .../Tasks/ReadLibraryProjectImportsCache.cs | 5 + .../Tasks/ResolveLibraryProjectImports.cs | 131 +++++++++++++----- .../Xamarin.Android.Build.Tests/BuildTest2.cs | 19 +++ .../Utilities/ELFHelper.cs | 22 ++- .../Xamarin.Android.EmbeddedResource.targets | 3 +- 9 files changed, 192 insertions(+), 70 deletions(-) diff --git a/Documentation/docs-mobile/messages/xa0141.md b/Documentation/docs-mobile/messages/xa0141.md index 15bb99a6d04..32421c5d3bd 100644 --- a/Documentation/docs-mobile/messages/xa0141.md +++ b/Documentation/docs-mobile/messages/xa0141.md @@ -1,14 +1,28 @@ --- title: .NET for Android warning XA0141 description: XA0141 warning code -ms.date: 22/07/2024 +ms.date: 01/08/2025 --- # .NET for Android warning XA0141 ## Issue -NuGet package '{0}' version '{1}' contains a shared library '{2}' which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details +Future versions of Android on arm64 will require that native libraries use 16 KB page sizes. +This requires that the mentioned native libraries be recompiled, and all apps using those +native libraries be rebuilt to contain the fixed versions of the native libraries. + +See the Android SDK [Support 16 KB page sizes](https://developer.android.com/guide/practices/page-sizes) +documentation for more information. ## Solution -The indicated native shared library must be recompiled and relinked with the 16k alignment, as per URL indicated in the message. +The indicated native shared library must be recompiled and relinked with the 16k alignment, as per +the Android SDK [Support 16 KB page sizes](https://developer.android.com/guide/practices/page-sizes) +documentation. + +## Example messages + +> warning XA0141: Android 16 will require 16 KB page sizes, Shared library 'libface_detector_v2_jni.so' does not have a 16 KB page size. +> Please inform the authors of the NuGet package 'Xamarin.GooglePlayServices.Vision.Face.Contour.Internal' version '116.1.0.19' +> which contains 'lib/net8.0-android34.0/play-services-vision-face-contour-internal.aar'. +> See https://developer.android.com/guide/practices/page-sizes for more details. diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AndroidLibraries.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AndroidLibraries.targets index 7d9f0e930a7..14b9e8c2dee 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AndroidLibraries.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AndroidLibraries.targets @@ -23,7 +23,7 @@ projects. <_AarSearchDirectory Include="@(_ReferencePath->'%(RootDir)%(Directory)')" /> <_AarSearchDirectory Include="@(_ReferenceDependencyPaths->'%(RootDir)%(Directory)')" /> <_AarDistinctDirectory Include="@(_AarSearchDirectory->Distinct())" /> - <_AarFromLibraries Include="%(_AarDistinctDirectory.Identity)*.aar" /> + <_AarFromLibraries Include="%(_AarDistinctDirectory.Identity)*.aar" NuGetPackageId="%(_AarDistinctDirectory.NuGetPackageId)" NuGetPackageVersion="%(_AarDistinctDirectory.NuGetPackageVersion)"/>