构建为可执行文件 main.rs 而不是 lib.rs 时没有链接错误
错误: 与 C:/Users/nafan/AppData/Local/ndk/26.2.11394342/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android34-clang++.cmd 链接失败:退出代码:255
注意:--version-script=C:\Users afan\AppData\Local\Temp ustcfcjtoe\list"" 这时候出乎意料了
config.toml
[target.aarch64-linux-android]
ar = "C:/Users/nafan/AppData/Local/ndk/26.2.11394342/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android34-clang++"
linker = "C:/Users/nafan/AppData/Local/ndk/26.2.11394342/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android34-clang++.cmd"
Cargo.toml
[lib]
name = "renderer"
crate-type = ["cdylib"]
[dependencies]
jni = "0.21.1"
lib.rs
use jni::{objects::JClass, sys::jint, JNIEnv};
#[no_mangle]
pub extern "C" fn Java_com_example_myapp_RustInterface_rustFunction(_env: JNIEnv, _class: JClass) -> jint {
let value = 42; // Example value
// Convert the value to JNI jint and return it
value as jint
}
可能的解决方法是稍微更改 aarch64-linux-android34-clang++.cmd 内容
https://github.com/android/ndk/issues/1856#issuecomment-1542248775