-
Notifications
You must be signed in to change notification settings - Fork 524
Description
Problem
Using fresh installations of Rust installed on x86_64-unknown-linux-gnu (Debian 10) via the rustup method, compiling packages for Android with NDK r23b (the current LTS release) does not work.
Steps
-
curl -sf -L https://static.rust-lang.org/rustup.sh | sh
(fresh install for the local user) -
rustup target add aarch64-linux-android
-
Create an empty library crate that depends on
ring
:
cargo new --lib hello
echo 'ring = "0.16"' >>hello/Cargo.toml
- Compile for the host and all is well:
$ cargo build
Updating crates.io index
Compiling libc v0.2.107
Compiling cc v1.0.72
Compiling once_cell v1.8.0
Compiling spin v0.5.2
Compiling untrusted v0.7.1
Compiling ring v0.16.20
Compiling hello v0.1.0 (/home/.../hello)
Finished dev [unoptimized + debuginfo] target(s) in 7.48s
- Compile for
aarch64-linux-android
the simple, documented way and it fails, but that's because of all the reasons in Build and link issues on Linux hosts with newer Android NDKs #459:
$ cargo build --target aarch64-linux-android
Compiling untrusted v0.7.1
Compiling spin v0.5.2
Compiling once_cell v1.8.0
Compiling libc v0.2.107
Compiling ring v0.16.20
error: failed to run custom build command for `ring v0.16.20`
Caused by:
process didn't exit successfully: `/home/.../hello/target/debug/build/ring-b1c7634ecf998ee6/build-script-build` (exit status: 101)
...
- Add all the workarounds from Build and link issues on Linux hosts with newer Android NDKs #459 and it still doesn't work:
$ PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/:$PATH \
CC_aarch64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang \
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang \
cargo build --lib --release --target aarch64-linux-android
Compiling ring v0.16.20
error: failed to run custom build command for `ring v0.16.20`
Caused by:
process didn't exit successfully: `/home/.../hello/target/release/build/ring-14a8ac965b8995d8/build-script-build` (exit status: 1)
...
--- stdout
running: "aarch64-linux-android-ar" "cq" ...
...
--- stderr
error occurred: Failed to find tool. Is `aarch64-linux-android-ar` installed?
The newest versions of the Android NDK simply do not ship GNU binutils and thus there is no aarch64-linux-android-ar
to use. No amount of changing paths or environment variables is likely to make this work. I suspect that the rust toolchain will need to use llvm-ar
and the other LLVM tools instead if it is to work with the current LTS versions of the Android NDK.
Activity
TroyNeubauer commentedon Jan 11, 2022
Same issue here. Would love to see a fix to allow me to use the current version of the NDK
sshxmz commentedon Feb 14, 2022
Same problem here.
outdated profile for cc::build:
default compiler = 'aarch64-linux-android21-clang'
default archiver = 'aarch64-linux-android-ar'
rileyhawk1417 commentedon Feb 18, 2022
Does version 22/21 have the files. Was hesitant after downloading via Android studio and manually downloading the NDK archive from the website.
[Edit]
Found what I was looking for. Hopefully this issue gets attention, will just be using version 22 for now.
dot-asm commentedon Mar 11, 2022
Would you mind testing a variant of #657? "A variant" means that I would have to prepare a variant that would extend the suggested approach to android targets.
dot-asm commentedon Mar 14, 2022
In the context I also wonder how do you specify the compiler? The background for the question is following. My understanding is that you're supposed to specify
linker
through .cargo/config.toml. In which case it would be only natural to use it even as default C compiler and use it to derive C++ compiler name...irediaes commentedon Mar 22, 2022
To fix copy and rename
llvm-ar
toaarch64-linux-android-ar
in${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/{SYSTEM}/bin
Do this for all your target arch.
b-spencer commentedon Mar 22, 2022
@irediaes Thanks for the information!
Armed with this tip, I guessed that I can also set an
AR_*
variable just likeCC_*
in my current list of workarounds.Taking the command from my item 6 above (in the first comment) and adding
AR_aarch64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
to it seems to make the build succeed.
I don't understand why rust's tools' expectations don't align with how the Android NDK ships, but it seems that at least I can configure it to work without modifying the Android NDK itself.
I'll leave this issue open in the hopes that either the rust toolchain will adapt to the NDK such that no workarounds at all are required, or at least that how to do this becomes documented somewhere.
Thanks again for the key information.
dot-asm commentedon Mar 25, 2022
Isn't answer to all these questions
cargo install cargo-apk
?It has nothing to do with Android. If you want to cross-compile for any platform, it is your responsibility to specify appropriate cross-linker. You can do it yourself or use helpers like
cargo-apk
. (Just in case, no, one can'tdochoose linker in a build script, it's too late.)arm-linux-androideabi-ar
not installed. #667briansmith commentedon Sep 27, 2024
Should this be closed? Everything in the description is so outdated that it is hard to see if it has any relevance today.
NobodyXu commentedon Sep 28, 2024
Thanks, I've closed this.
If anyone still encounters this issue, feel free to open a new issue.