runtime: Unable to publish NativeAOT project for linux-bionic-arm64
Description
Building a simple Hello World sample works for the linux-bionic-x64 and linux-bionic-arm64 rids, but publishing AOT fails for linux-bionic-arm64, but works for linux-bionic-x64. The following error is thrown immediately when attempting the build,
/home/emmaus/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.0-preview.6.23307.4/build/Microsoft.NETCore.Native.Publish.targets(75,5): error : The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative [/home/emmaus/test/test.csproj]
Reproduction Steps
A simple project with the required nuget packages already referenced here, https://github.com/emmauss/test-aot.
Restore and build it with
dotnet publish -r linux-bionic-arm64 -c Debug -p:SysRoot=/.tools/android-rootfs/android-ndk-r21/sysroot. The error is immediately thrown.
Expected behavior
The project quickly builds and a compatible executable is generated.
Actual behavior
The following error is displayed,
/home/emmaus/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.0-preview.6.23307.4/build/Microsoft.NETCore.Native.Publish.targets(75,5): error : The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative [/home/emmaus/test/test.csproj]
Regression?
No response
Known Workarounds
No response
Configuration
OS: Fedora 38 on WSL2 running on Windows 11 x64 host .Net Version: 8.0.0-preview.6.23307.4 daily build
Other information
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 39 (22 by maintainers)
Commits related to this issue
- Include liblog in linker command line for Bionic Fixes issue reported in https://github.com/dotnet/runtime/issues/87340#issuecomment-1600401747. — committed to dotnet/runtime by MichalStrehovsky a year ago
- Include liblog in linker command line for Bionic (#87862) Fixes issue reported in https://github.com/dotnet/runtime/issues/87340#issuecomment-1600401747. — committed to dotnet/runtime by MichalStrehovsky a year ago
- Use LLD linker when targeting Bionic https://github.com/dotnet/runtime/issues/87340#issuecomment-1612561061 — committed to dotnet/runtime by MichalStrehovsky a year ago
- Use LLD linker when targeting Bionic (#88179) https://github.com/dotnet/runtime/issues/87340#issuecomment-1612561061 — committed to dotnet/runtime by MichalStrehovsky a year ago
- Add docs on using Bionic with NativeAOT Resolves #87340. — committed to MichalStrehovsky/runtime by MichalStrehovsky a year ago
- Add docs on using Bionic with NativeAOT (#88817) Resolves #87340. — committed to dotnet/runtime by MichalStrehovsky a year ago
Thanks for confirming! #88179 should fix this.
Thanks for confirming - I created #87862 to include this by default when targeting Bionic. Once that merges and propagates through the systems, the workaround won’t be needed.
It’s possible to try this out now:
setwithexportfor Linux):bin\Debug\net8.0\linux-bionic-arm64\publish. Copy this to an Android device. Eitheradb pushor using some GUI.adb shell, but I used Termux: open Termux, give it access to file system by runningtermux-setup-storage. This will give you access to phone storage under~/storage. Copy the binary from~/storage/...to~(internal storage is not executable and you won’t be able to run stuff from it). Thenchmod +x HelloBionicand./HelloBionic. You should see Hello World. There will also be a warning, that one is also fixed and will be in dotnet/installer in a day or two.The more interesting variation of this is building shared libraries that you can call into with JNI. There’s a sample for that at https://github.com/josephmoresena/NativeAOT-AndroidHelloJniLib. The instructions obviously don’t explain how to use this with today’s bits, but @josephmoresena should be able to greatly simplify it soon (or you can send a PR).
Cc @kekekeks @maxkatz6
Setting <LinkerFlavor>lld</LinkerFlavor> makes it build successfully with ndk 25
We can deal with that problem once/if Unity runs into it. This is not the only place where Android treatment is debatable today. For example,
OperatingSystem.IsLinux()returns false for Android RID with Java interop today.Adding this works, and I’m able to call functions from the library. Thanks.
Can you try adding this to the project file, delete obj and bin directories and publish again?