Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Building fails with Android NDK r22 on OSX? #55412

Closed
lambdageek opened this issue Jul 9, 2021 · 9 comments · Fixed by #64226
Closed

[Android] Building fails with Android NDK r22 on OSX? #55412

lambdageek opened this issue Jul 9, 2021 · 9 comments · Fixed by #64226

Comments

@lambdageek
Copy link
Member

  1. Download Android NDK r22
  2. Build with export ANDROID_NDK_ROOT=/path/to/android-ndk-r22 ./build.sh --os android --arch x64 -c Release

Expected:

Build succeeds

Actual:

EXEC : error : /Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.Native.a the table of contents is empty (no object file members in the library define global symbols) [/Users/alklig/work/dotnet-runtime/runtime-bugs/src/libraries/Native/build-native.proj]
EXEC : error : /Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.Security.Cryptography.Native.Android.a the table of contents is empty (no object file members in the library define global symbols) [/Users/alklig/work/dotnet-runtime/runtime-bugs/src/libraries/Native/build-native.proj]
EXEC : error : /Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.IO.Compression.Native.a the table of contents is empty (no object file members in the library define global symbols) [/Users/alklig/work/dotnet-runtime/runtime-bugs/src/libraries/Native/build-native.proj]

Build fails while linking libSystem.Native.a with:

Note that it's Xcode's linker that is complaining. So something about the toolchain detection is not picking up the linker from the NDK and falling back to whatever it finds on the PATH.

Possibly see #51876 which attempted to support r22 apparently did not get everything.


I have this in ndk/source.properties

Pkg.Desc = Android NDK
Pkg.Revision = 22.0.7026061

Have not tried the latest r22b 22.1.7171670 at this time.

@dotnet-issue-labeler dotnet-issue-labeler bot added area-Infrastructure-libraries untriaged New issue has not been triaged by the area owner labels Jul 9, 2021
@ghost
Copy link

ghost commented Jul 9, 2021

Tagging subscribers to this area: @Anipik, @safern, @ViktorHofer
See info in area-owners.md if you want to be subscribed.

Issue Details
  1. Download Android NDK r22
  2. Build with export ANDROID_NDK_ROOT=/path/to/android-ndk-r22 ./build.sh --os android --arch x64 -c Release

Expected:

Build succeeds

Actual:

EXEC : error : /Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.Native.a the table of contents is empty (no object file members in the library define global symbols) [/Users/alklig/work/dotnet-runtime/runtime-bugs/src/libraries/Native/build-native.proj]
EXEC : error : /Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.Security.Cryptography.Native.Android.a the table of contents is empty (no object file members in the library define global symbols) [/Users/alklig/work/dotnet-runtime/runtime-bugs/src/libraries/Native/build-native.proj]
EXEC : error : /Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.IO.Compression.Native.a the table of contents is empty (no object file members in the library define global symbols) [/Users/alklig/work/dotnet-runtime/runtime-bugs/src/libraries/Native/build-native.proj]

Build fails while linking libSystem.Native.a with:

Note that it's Xcode's linker that is complaining. So something about the toolchain detection is not picking up the linker from the NDK and falling back to whatever it finds on the PATH.

Possibly see #51876 which attempted to support r22 apparently did not get everything.


I have this in ndk/source.properties

Pkg.Desc = Android NDK
Pkg.Revision = 22.0.7026061

Have not tried the latest r22b 22.1.7171670 at this time.

Author: lambdageek
Assignees: -
Labels:

area-Infrastructure-libraries, untriaged

Milestone: -

@ghost
Copy link

ghost commented Jul 9, 2021

Tagging subscribers to this area: @directhex
See info in area-owners.md if you want to be subscribed.

Issue Details
  1. Download Android NDK r22
  2. Build with export ANDROID_NDK_ROOT=/path/to/android-ndk-r22 ./build.sh --os android --arch x64 -c Release

Expected:

Build succeeds

Actual:

EXEC : error : /Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.Native.a the table of contents is empty (no object file members in the library define global symbols) [/Users/alklig/work/dotnet-runtime/runtime-bugs/src/libraries/Native/build-native.proj]
EXEC : error : /Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.Security.Cryptography.Native.Android.a the table of contents is empty (no object file members in the library define global symbols) [/Users/alklig/work/dotnet-runtime/runtime-bugs/src/libraries/Native/build-native.proj]
EXEC : error : /Applications/Xcode_12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.IO.Compression.Native.a the table of contents is empty (no object file members in the library define global symbols) [/Users/alklig/work/dotnet-runtime/runtime-bugs/src/libraries/Native/build-native.proj]

Build fails while linking libSystem.Native.a with:

Note that it's Xcode's linker that is complaining. So something about the toolchain detection is not picking up the linker from the NDK and falling back to whatever it finds on the PATH.

Possibly see #51876 which attempted to support r22 apparently did not get everything.


I have this in ndk/source.properties

Pkg.Desc = Android NDK
Pkg.Revision = 22.0.7026061

Have not tried the latest r22b 22.1.7171670 at this time.

Author: lambdageek
Assignees: -
Labels:

area-Infrastructure-mono, untriaged

Milestone: -

@lambdageek
Copy link
Member Author

/cc @akoeplinger @steveisok

@steveisok steveisok removed the untriaged New issue has not been triaged by the area owner label Jul 9, 2021
@steveisok steveisok added this to the 7.0.0 milestone Jul 9, 2021
@MaximLipnin
Copy link
Contributor

Have not tried the latest r22b 22.1.7171670 at this time.

I tried it on BigSur 11.2.3 using the 22.1.7171670 NDK version, which came with Android Studio, and got similar error:

EXEC : error : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.Native.a the table of contents is empty (no object file members in the library define global symbols) [/Users/maxim/dev/runtime/src/libraries/Native/build-native.proj]
EXEC : error : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.Security.Cryptography.Native.Android.a the table of contents is empty (no object file members in the library define global symbols) [/Users/maxim/dev/runtime/src/libraries/Native/build-native.proj]
EXEC : error : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libSystem.IO.Compression.Native.a the table of contents is empty (no object file members in the library define global symbols) [/Users/maxim/dev/runtime/src/libraries/Native/build-native.proj]
resource ILLink.Descriptors.xml in System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e(545,6): error IL2008: Could not resolve type 'System.Threading.AutoreleasePool' [/Users/maxim/dev/runtime/src/libraries/src.proj]

@MaximLipnin
Copy link
Contributor

@grendello Do you happen to know how to address this issue?

@grendello
Copy link
Contributor

@MaximLipnin r22 moved stuff around. Also, if the build uses generated toolchains, they won't work. Build must use the toolchain found in [NDK_ROOT]/toolchains/llvm/prebuilt/[HOST_OS-ARCH]/bin. If cmake is used, then it's best to use the Android cmake toolchain from [NDK_ROOT]/build/cmake/android.toolchain. Xcode linker won't find anything in the archive that it knows, since the object files there will be in ELF format (since they're for Linux/Android) and not the macOS Mach format. You can see how Xamarin.Android does it here and here.

@lambdageek
Copy link
Member Author

@grendello The weird thing is that the build of libmono works, but System.Native ends up using Xcode's ranlib. And they both use the android.toolchain.cmake file - here's System.Native, I think -

__CMakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_STL=none -DANDROID_NATIVE_API_LEVEL=21 $__CMakeArgs"

@grendello
Copy link
Contributor

huh, that IS weird

@directhex directhex changed the title [Android] Building fails with Android NDK r22 (on OSX?) [Android] Building fails with Android NDK r22 on OSX? Jan 24, 2022
directhex added a commit to directhex/runtime that referenced this issue Jan 24, 2022
In some cases, CMAKE_CXX_COMPILER_ID might not be populated,
which causes the toolchaine prefix checks to be ignored, which
causes the build to look for `ranlib` not `llvm-ranlib`, which
causes it to use XCode ranlib instead of Android NDK ranlib for
builds, which doesn't work.

Hopefully (we'll see what CI says) this doesn't regress other builds.

Closes: dotnet#55412
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 24, 2022
@directhex
Copy link
Member

PR to fix this is linked above.

r23 patch (tested on Linux and macOS):

diff --git a/src/mono/mono.proj b/src/mono/mono.proj
index c7febf933f5..cf0e09dff2d 100644
--- a/src/mono/mono.proj
+++ b/src/mono/mono.proj
@@ -518,7 +518,7 @@
       <_Objcopy Condition="'$(Platform)' == 's390x'">s390x-linux-$(_LinuxAbi)-$(_Objcopy)</_Objcopy>
       <_Objcopy Condition="'$(Platform)' == 'x64'">x86_64-linux-$(_LinuxAbi)-$(_Objcopy)</_Objcopy>
       <_Objcopy Condition="'$(Platform)' == 'x86'">i686-linux-$(_LinuxAbi)-$(_Objcopy)</_Objcopy>
-      <_Objcopy Condition="'$(TargetsAndroid)' == 'true'">$(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/$(MonoToolchainPrebuiltOS)/bin/$(_Objcopy)</_Objcopy>
+      <_Objcopy Condition="'$(TargetsAndroid)' == 'true'">$(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/$(MonoToolchainPrebuiltOS)/bin/llvm-objcopy</_Objcopy>
     </PropertyGroup>
     <!-- test viability of objcopy command -->
     <Exec Condition="'$(BuildMonoAOTCrossCompilerOnly)' != 'true' and ('$(TargetsLinux)' == 'true' or '$(TargetsAndroid)' == 'true')" Command="$(_Objcopy) -V" IgnoreStandardErrorWarningFormat="true" ContinueOnError="WarnAndContinue" IgnoreExitCode="true" EchoOff="true" ConsoleToMsBuild="true">

directhex added a commit that referenced this issue Jan 28, 2022
* Check for CMAKE_C_COMPILER_ID not CXX

In some cases, CMAKE_CXX_COMPILER_ID might not be populated,
which causes the toolchaine prefix checks to be ignored, which
causes the build to look for `ranlib` not `llvm-ranlib`, which
causes it to use XCode ranlib instead of Android NDK ranlib for
builds, which doesn't work.

Hopefully (we'll see what CI says) this doesn't regress other builds.

Closes: #55412

* Update eng/native/configuretools.cmake

Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>

* Use llvm-objcopy, not GNU, on Android

It's available in r21 (which we use today) and works for r23
(which has no GNU objcopy any more and breaks without this change)

Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 28, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Feb 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants