参考资料:
https://kaisery.github.io/trpl-zh-cn/ch01-01-installation.html
https://blog.rust-lang.org/2016/05/13/rustup.html
https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-21-rust-on-android.html
https://ghotiphud.github.io/rust/android/cross-compiling/2016/01/06/compiling-rust-to-android.html
https://logankeenan.com/posts/cross-platform-rust-database-access-android/
https://github.com/rust-windowing/android-ndk-rs
0.安装rust
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
1.安装Android NDK
/home/softsim/Android/Sdk/ndk/22.0.7026061
2. 添加target
rustup target add aarch64-linux-android rustup target add armv7-linux-androideabi rustup target list
3. 配置toolchain
编辑 ~/.cargo/config
[build] target = "armv7-linux-androideabi" [target.armv7-linux-androideabi] linker = "/home/softsim/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi27-clang" [target.aarch64-linux-android] linker = "/home/softsim/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android27-clang"
NDK 23以上,去掉了 libgcc, 编译不通过,需要手动加上 libgcc
4.创建工程
cargo new --bin hello && cd hello cargo build cargo build --target aarch64-linux-android --release --verbose Compiling hello v0.1.0 (/home/softsim/workspace/hello) Running `rustc --crate-name hello --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no -C metadata=fca5cedcba8d4943 -C extra-filename=-fca5cedcba8d4943 --out-dir /home/softsim/workspace/hello/target/aarch64-linux-android/release/deps --target aarch64-linux-android -C linker=/home/softsim/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android27-clang -L dependency=/home/softsim/workspace/hello/target/aarch64-linux-android/release/deps -L dependency=/home/softsim/workspace/hello/target/release/deps` Finished release [optimized] target(s) in 0.26s