jedisct1 / libsodium

A modern, portable, easy to use crypto library.

Home Page:https://libsodium.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linker command failed - android-armv7 script

cmonfortep opened this issue · comments

I'm trying to run the script to generate an aar for Android, and I'm getting an error when the script tries to compile the library on the armv7 architecture.

First I tried executing android-aar.sh script, and it generated an aar but armv7 failed.
Then I tried executing android-armv7-a.sh, and I get a bunch of errors (e.g: libaesni.a: member at 8 is not an ELF object), with a final clang error saying linker command failed with exit code 1.

Rest of the architectures script work without issues (arm8, x86, and x86_64), so I assume this is something specific of armv7.

Also, in case it helps, I'm running those scripts from MacBook pro, darwin kernel x86_64.

Everything seems to be fine in CI:

android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Update packages list
run: sudo apt-get update
- name: Install base dependencies
run: sudo apt-get install -y libtool autoconf automake unzip
- name: Autogen
run: ./autogen.sh -s
- name: Install Android NDK
run: |
mkdir /tmp/android && cd /tmp/android
curl -o ndk.zip -L https://dl.google.com/android/repository/android-ndk-r25b-linux.zip
unzip ndk.zip && rm -f *.zip && mv android-ndk* ndk
- name: Android compilation
run: |
env ANDROID_NDK_HOME=/tmp/android/ndk ./dist-build/android-aar.sh

https://github.com/jedisct1/libsodium/actions/runs/4009408847/jobs/6884725366

Are you using the same NDK version? (r25b)

I just successfully compiled the armv7 version on an x86-64 macbook pro using the latest from git and the latest ndk (25.1.8937393 which I believe is the same as r25b). @cmonfortep please confirm you are also using the latest from git and the latest ndk. Also do you maybe have more than one ndk installed or alternatively have you modified the ndk in anyway or done anything that could have done so? My best guess is a corrupted ndk if you haven't deliberately changed it try uninstalling and reinstalling the ndk and see if the issue is fixed.

Thanks for the quick response.
The latest version of git, yes. But an old version of ndk (21.4.7075529, we use that version to compile other internal c libraries). I've just downloaded ndk version 25 and I confirm it works.

So that confirms the issue is the ndk version I was using. I will need to check with the team if we can bump ndk version. Are you aware of why using ndk 25 fixes it?

The quick answer is that the toolchain was before the current aar script was written so it was never tested against. I'm more surprised that any of the scripts work to be honest the old libsodium scripts used to create toolchains for each platform, which was the legacy approach to the ndk (it was pretty crazy you'd have a huge toolchain directory structure created for each version of each thing you'd compile). Looking at the ndk changelog it appears that the version you're using was a transitional version between the old and new approaches:

"The legacy toolchain install paths will be removed over the coming releases. These paths have been obsolete since NDK r19 and take up a considerable amount of space in the NDK. The paths being removed are"

So I'd guess that some important files moved around in the process or maybe even were added or renamed or something. It is likely possible to get it working either by modifying some flags in the current scripts or going back to the previous versions of the scripts and modifying them to work with the script that packs the outputs into the AAR. The old build scripts are still bundled in the stable release on the libsodium site.

Thanks for the explanation @ReenigneCA 👍