Android framework version
net10.0-android
Affected platform version
.NET SDK 10.0.x with the net10.0-android workload; also reproduced with Android workload 37.0.0-preview.6.59
Description
Xamarin.AndroidX.Graphics.Path 1.1.0.1 causes its native libandroidx.graphics.path.so payload to be embedded into every consuming Android class library's generated AAR. When that class library is packed as a NuGet, the NuGet also correctly retains Xamarin.AndroidX.Graphics.Path as a dependency. An application consuming the outer NuGet therefore receives the same native library twice and reports XA4301.
The MSBuild item flow is:
Xamarin.AndroidX.Graphics.Path.targets adds androidx.graphics.graphics-path.aar as AndroidAarLibrary.
_GetLibraryImports extracts its native files as AndroidNativeLibrary.
- For a class library,
_CategorizeAndroidLibraries copies every AndroidNativeLibrary to EmbeddedNativeLibrary.
_CreateAar passes all EmbeddedNativeLibrary items to CreateAar, embedding them into the outer library's generated AAR.
- NuGet packing includes that generated AAR and retains the package dependency, so an application receives both copies.
The two copies are byte-for-byte identical. This is not specific to Compose, but it is exposed by packing Microsoft.AndroidX.Compose, which depends transitively on Xamarin.AndroidX.Graphics.Path through Xamarin.AndroidX.Compose.UI.Graphics.Android.
A minimal reproduction is an Android class library with:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0-android</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.Graphics.Path" Version="1.1.0.1" />
</ItemGroup>
</Project>
Run dotnet pack and inspect the resulting package:
- The generated class-library AAR contains
jni/<abi>/libandroidx.graphics.path.so.
- The nuspec retains the
Xamarin.AndroidX.Graphics.Path dependency.
Consume that package from a net10.0-android application and build an APK. The application sees the native library both through the outer AAR and through Xamarin.AndroidX.Graphics.Path.
Expected behavior: a native asset already supplied by a retained NuGet dependency should not also be embedded in the consuming class library's AAR. This may require package-generation changes, an Android SDK item-metadata mechanism, or limiting runtime AAR inclusion to the final application without breaking class-library Java compilation.
We are working around this in Microsoft.AndroidX.Compose by removing libandroidx.graphics.path.so from EmbeddedNativeLibrary after _CategorizeAndroidLibraries and before _CreateAarCache. The package dependency remains, and the final APK still contains one copy per selected ABI.
Relevant log output
obj/Debug/net10.0-android/lp/203/jl/jni/x86_64/libandroidx.graphics.path.so : warning XA4301: APK already contains the item lib/x86_64/libandroidx.graphics.path.so; ignoring.
obj/Debug/net10.0-android/lp/203/jl/jni/arm64-v8a/libandroidx.graphics.path.so : warning XA4301: APK already contains the item lib/arm64-v8a/libandroidx.graphics.path.so; ignoring.
Android framework version
net10.0-android
Affected platform version
.NET SDK 10.0.x with the net10.0-android workload; also reproduced with Android workload 37.0.0-preview.6.59
Description
Xamarin.AndroidX.Graphics.Path 1.1.0.1causes its nativelibandroidx.graphics.path.sopayload to be embedded into every consuming Android class library's generated AAR. When that class library is packed as a NuGet, the NuGet also correctly retainsXamarin.AndroidX.Graphics.Pathas a dependency. An application consuming the outer NuGet therefore receives the same native library twice and reports XA4301.The MSBuild item flow is:
Xamarin.AndroidX.Graphics.Path.targetsaddsandroidx.graphics.graphics-path.aarasAndroidAarLibrary._GetLibraryImportsextracts its native files asAndroidNativeLibrary._CategorizeAndroidLibrariescopies everyAndroidNativeLibrarytoEmbeddedNativeLibrary._CreateAarpasses allEmbeddedNativeLibraryitems toCreateAar, embedding them into the outer library's generated AAR.The two copies are byte-for-byte identical. This is not specific to Compose, but it is exposed by packing
Microsoft.AndroidX.Compose, which depends transitively onXamarin.AndroidX.Graphics.PaththroughXamarin.AndroidX.Compose.UI.Graphics.Android.A minimal reproduction is an Android class library with:
Run
dotnet packand inspect the resulting package:jni/<abi>/libandroidx.graphics.path.so.Xamarin.AndroidX.Graphics.Pathdependency.Consume that package from a
net10.0-androidapplication and build an APK. The application sees the native library both through the outer AAR and throughXamarin.AndroidX.Graphics.Path.Expected behavior: a native asset already supplied by a retained NuGet dependency should not also be embedded in the consuming class library's AAR. This may require package-generation changes, an Android SDK item-metadata mechanism, or limiting runtime AAR inclusion to the final application without breaking class-library Java compilation.
We are working around this in
Microsoft.AndroidX.Composeby removinglibandroidx.graphics.path.sofromEmbeddedNativeLibraryafter_CategorizeAndroidLibrariesand before_CreateAarCache. The package dependency remains, and the final APK still contains one copy per selected ABI.Relevant log output