Rust link android NDK R23 exception
1 What
Some times ago,there were numberous github actions errors in my Rust Hybrid Project,but I don’t have time to go through it。Just took time to look at it today,I found it was caused by -lgcc
linker. However, I haven’t pushed to this repository for long time, what would be the root cause?
note: ld: error: unable to find library -lgcc
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
2 Why
Although there is no clue, but the error is so obvious that it is not very difficult to find. So I looked for it from two directions, one is the Rust release notes, and the other is the update of the Github Actions environment.
The first is the Rust release notes. I searched and found nothing related to the update of Android and libgcc. Then change the direction, see what updates Github Actions has, and find the Github official document, this does not clearly say what version, just the LTS version. Then look again, there is a more detailed document. Rust is the latest version 1.62.1, and the NDK version is R25 by default. Is there a problem with the NDK version?
I followed the vines, combined these two information and searched again, and I found Issue finally, it turned out that libgcc was removed after NDK in r23, but Rust relies on this for providing missing builtins on Android.
3 How
It’s so easy to fix the issue when we know the root cause. Downgrade the NDK version will resolve this issue, we cannot use latest Rust version due to they don’t officially merge the fix to the stable release.
- uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r22b
add-to-path: true
- name: your build
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
Perfect❤️