Search code examples
androidwindowsrustcross-platform

Cross Compiling Rust Crate on Windows for Android


I'm trying to cross compile a practically empty library crate on Windows for Android. Sadly when doing so, I either get the error that the linker cc could not be found or when I try to use rust-lld to solve this issue, I get the linker complaining about missing libraries like -ldl, -lunwind or -llog.

As such I probably am missing something fundamental. My google Fu came up empty on how to solve this issue for Windows (without using WSL or Docker, which is basicly saying use Linux instead...). Can someone point me in the right direction or to an up-to-date tutorial for cross compiliation?

Any help is much appreciated.

Edit:

The concrete error I'm getting when compiling example_crate using the command cargo build --target x86_64-linux-android with a .cargo/config.toml changing the linker to rust-lld:

  = note: rust-lld: error: unable to find library -ldl
          rust-lld: error: unable to find library -llog
          rust-lld: error: unable to find library -lunwind
          rust-lld: error: unable to find library -ldl
          rust-lld: error: unable to find library -lm
          rust-lld: error: unable to find library -lc


error: could not compile `example_crate` due to previous error

I've created the example_crate using cargo init example_crate changed the main.rs to lib.rsand added crate-type = ["cdylib"] to the lib section in my Cargo.toml.


Solution

  • After some time i got back to this and found the very helpful cargo ndk command which solved the issue for me. It appears like there were issues with finding the Android NDK, and setting ANDROID_NDK_HOME fixed it.