By default, rustup will only install pre-compiled versions of the standard library for your host machine, so if you want to compile to other architectures or operating systems, you need to do rustup target add blah.
Thank you for your answer
I don't think this possibility exists because when I execute cargo build --target=aarch64-linux-android and cargo build in the same terminal, the result is that cargo build will build an error while cargo build --target=aarch64-linux-android will not.
It is exactly this problem. Rust installed from a Linux distro is not going to support rustup add, which means it will work fine without --target, and fail when --target for another architecture is used.
Sorry, I'm a bit confused. Both my Rust and Cargo were installed through rustup, and initially I followed the official instructions to complete the installation by executing the command "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" in the command line.
You have two rusts on your computer. A bad one that can't support Android no matter what you do, which is always going to break when you use --target for another platform, and a good one that has Android support installed, but which you are not using, because the bad one is taking over.
I see you're using macOS, so run:
brew uninstall rust
because Rust from Homebrew can't compile for Android. You are using Rust from Homebrew, and not Rust from rustup. Only Rust installed via rustup can be configured for cross-compilation via rustup commands.
Thank you very much for @kornel 's patient explanation. As you said, there were two versions of Rust installed on my computer, and I didn't even realize it. Following your advice, I removed Rust from Homebrew, and the problem was solved. Thank you again!
Android is a tier 2 target without host tools. This means that while we ship a precompiled standard library, we don't ship a precompiled rustc version for android. Using rustup requires a precompiled rustc version for the host shipped by the rust project.
I have the same problem, and after carefully examination, I found I installed 2 rust package at my computer. so when I run rustup and cargo, I am using 2 exe with diffent libs. Actually until today I can't say I figure out this problem totally, but after reinstall the rust I solve my problem and it work well until now. If you have same problem, please carefully examine all the folders where you install rust and check the PATH
environmental variable as well.