Skip to content

Xamarin.Google.MLKit.BarcodeScanning packages barcode-scanning 17.3.0 twice (embedded AAR + XamarinBuildDownload), causing duplicate XA4301 warnings #1519

Description

@ThisIsDavidHan

Android framework version

net9.0-android

Affected platform version

.NET SDK 9.0.316, macOS 15 (Apple Silicon)

Description

Xamarin.Google.MLKit.BarcodeScanning includes the Google Maven artifact com.google.mlkit:barcode-scanning:17.3.0 twice, which produces XA4301 duplicate-native-library warnings in every Android build that references the package (directly or transitively, e.g. via BarcodeScanning.Native.Maui):

obj/Debug/net9.0-android36.0/lp/260/jl/jni/arm64-v8a/libbarhopper_v3.so : warning XA4301: APK already contains the item lib/arm64-v8a/libbarhopper_v3.so; ignoring.
obj/Debug/net9.0-android36.0/lp/260/jl/jni/arm64-v8a/libbarhopper_v3.so : warning XA4301: APK already contains the item lib/arm64-v8a/libbarhopper_v3.so; ignoring.

The two copies come from the same NuGet package through two different mechanisms:

  1. The AAR embedded in the package itself: lib/net9.0-android35.0/barcode-scanning.aar (extracted to obj/.../lp/228 in my build).
  2. The same artifact downloaded again at build time by Xamarin.Build.Download: buildTransitive/net9.0-android35.0/Xamarin.Google.MLKit.BarcodeScanning.targets declares a XamarinBuildDownload item for https://dl.google.com/dl/android/maven2/com/google/mlkit/barcode-scanning/17.3.0/barcode-scanning-17.3.0.aar (extracted to obj/.../lp/260).

Mapping evidence from obj/Debug/net9.0-android36.0/libraryimports.cache:

lp/228 <- ~/.nuget/packages/xamarin.google.mlkit.barcodescanning/117.3.0.3/lib/net8.0-android34.0/barcode-scanning.aar
lp/260 <- ~/Library/Caches/XamarinBuildDownload/barcodescanning-17.3.0/barcodescanning-17.3.0.aar

On top of that, the targets file adds the downloaded AAR to the item group twice (identical consecutive lines), which is why the XA4301 warning is emitted twice per ABI:

<ItemGroup>
  <XamarinBuildDownloadAndroidAarLibrary Include="$(XamarinBuildDownloadDir)barcodescanning-17.3.0\barcodescanning-17.3.0.aar" />
  <XamarinBuildDownloadAndroidAarLibrary Include="$(XamarinBuildDownloadDir)barcodescanning-17.3.0\barcodescanning-17.3.0.aar" />
</ItemGroup>

I verified the same double-inclusion (embedded lib/**/barcode-scanning.aar + XamarinBuildDownload of the same artifact, with the doubled item line) is present in the latest release 117.3.0.8, in both the net9.0-android35.0 and net10.0-android36.0 targets, so all currently shipping versions are affected (checked 117.3.0.3 and 117.3.0.8).

Expected: the artifact is included once — either embedded in lib/ or fetched via XamarinBuildDownload, not both — and the XamarinBuildDownloadAndroidAarLibrary item is not duplicated inside the targets.

Related: xamarin/GooglePlayServicesComponents#819 reported the same warnings; it was closed without the source of the duplication being identified.

Steps to Reproduce

  1. dotnet new maui
  2. Add <PackageReference Include="Xamarin.Google.MLKit.BarcodeScanning" Version="117.3.0.8" /> (or BarcodeScanning.Native.Maui, which depends on it)
  3. dotnet build -f net9.0-android
  4. Observe the duplicated XA4301 warnings for libbarhopper_v3.so (one pair per ABI being packaged)

Did you find any workaround?

The warning is cosmetic — packaging keeps the first copy and drops the duplicate, so the APK is correct. <NoWarn>$(NoWarn);XA4301</NoWarn> silences it.

Relevant log output

Restore complete (0.6s)
  MyApp net9.0-android36.0 succeeded with 2 warning(s) (57.7s) → src/bin/Debug/net9.0-android36.0/MyApp.dll
    obj/Debug/net9.0-android36.0/lp/260/jl/jni/arm64-v8a/libbarhopper_v3.so : warning XA4301: APK already contains the item lib/arm64-v8a/libbarhopper_v3.so; ignoring.
    obj/Debug/net9.0-android36.0/lp/260/jl/jni/arm64-v8a/libbarhopper_v3.so : warning XA4301: APK already contains the item lib/arm64-v8a/libbarhopper_v3.so; ignoring.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions