Skip to content

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

Description

@lambdageek
  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.

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Jul 9, 2021
  2. lambdageek commented on Jul 9, 2021

    @lambdageek
    MemberAuthor
  3. removed
    untriagedNew issue has not been triaged by the area owner
    on Jul 9, 2021
  4. added this to the 7.0.0 milestone on Jul 9, 2021
  5. MaximLipnin commented on Jul 15, 2021

    @MaximLipnin
    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]
    
    
  6. MaximLipnin commented on Jul 15, 2021

    @MaximLipnin
    Contributor

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

  7. grendello commented on Jul 15, 2021

    @grendello
    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.

  8. lambdageek commented on Jul 15, 2021

    @lambdageek
    MemberAuthor

    @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"

  9. grendello commented on Jul 15, 2021

    @grendello
    Contributor

    huh, that IS weird

  10. changed the title [-][Android] Building fails with Android NDK r22 (on OSX?)[/-] [+][Android] Building fails with Android NDK r22 on OSX?[/+] on Jan 24, 2022
  11. added a commit that references this issue on Jan 24, 2022
    ee1309f
  12. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 24, 2022
  13. directhex commented on Jan 24, 2022

    @directhex
    Contributor

    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">
    
  14. added a commit that references this issue on Jan 28, 2022
    c7adf55
  15. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 28, 2022
  16. ghost locked as resolved and limited conversation to collaborators on Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions