dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 528 forks source link

_CreateAar step fails if you also have native libraries intended for Linux #8466

Open busec0 opened 1 year ago

busec0 commented 1 year ago

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

.NET 7.0.308

Description

Given an SDK project targeting:

<TargetFrameworks>netstandard2.1;net6.0-ios;net6.0-android</TargetFrameworks>

And intended to be used on Android but also Linux, with native libraries, having the following structure:

libs
├── android
│   ├── arm64-v8a
│   │   └── lib.so
│   ├── armeabi-v7a
│   │   └── lib.so
│   ├── x86
│   │   └── lib.so
│   └── x86_64
│       └── lib.so
└── linux
    ├── linux-aarch64
    │   └── lib.so
    └── linux-x86_64
        └── lib.so

Trying to build it, it fails with the given error, during the _CreateAar step

libs/linux/linux-aarch64/lib.so : error XA4301: Cannot determine ABI of native library 'libs/linux/linux-aarch64/lib.so'. Move this file to a directory with a valid Android ABI name such as 'libs/armeabi-v7a/'.
libs/linux/linux-x86_64/lib.so : error XA4301: Cannot determine ABI of native library 'libs/linux/linux-x86_64/lib.so'. Move this file to a directory with a valid Android ABI name such as 'libs/armeabi-v7a/'.

Even excluding the files has no effect.

<None Remove="libs\linux\linux-x86_64\lib.so" />
<None Remove="libs\linux\linux-aarch64\lib.so" />

Steps to Reproduce

  1. Create a Microsoft.NET.Sdk project targeting net6.0-android
  2. Create the libs structure defined in the description.
  3. Try to build and notice the failure.

Did you find any workaround?

Just dirty hacks to be used around the _CreateAar step to avoid these being identified by the pattern libs/[arch]/*.so

Relevant log output

libs/linux/linux-aarch64/lib.so : error XA4301: Cannot determine ABI of native library 'libs/linux/linux-aarch64/lib.so'. Move this file to a directory with a valid Android ABI name such as 'libs/armeabi-v7a/'.
libs/linux/linux-x86_64/lib.so : error XA4301: Cannot determine ABI of native library 'libs/linux/linux-x86_64/lib.so'. Move this file to a directory with a valid Android ABI name such as 'libs/armeabi-v7a/'.
busec0 commented 1 year ago

This should probably give you a warning and not fail the build or ignore it if you have linux in the name.

jonathanpeppers commented 1 year ago

Your <None Remove=""/> lines are on the right track, but I think this wildcard is picking them up:

https://github.com/xamarin/xamarin-android/blob/d5c4ec09f7658428a10bbe49c8a7a3eb2f71cb86/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/Sdk/AutoImport.props#L57

So, you would need to use AndroidNativeLibrary Remove="... instead of None.

I think maybe the fix is we somehow put Exclude="*linux*" in the default wildcard?

busec0 commented 11 months ago

@jonathanpeppers Thanks! Using AndroidNativeLibrary did it, so I can ignore the linux bits manually.

I agree, something like Exclude="*linux*" should be fine - even though that depends on the folder structure, so I'd also find important properly documenting this - making the AndroidNativeLibraryRemove="... more visible.