Pkg-config errors when trying to cross-compile for android

I'm trying to cross-compile for android but I am getting the following errors. Does anyone know what I am doing wrong?

error: failed to run custom build command for glib-sys v0.10.1

Caused by:
process didn't exit successfully: /home/martin/git/shatin-srs/shatin-c/target/debug/build/glib-sys-7dd7f5ee8e033e47/build-script-build (exit status: 1)
--- stdout

--- stderr
pkg-config has not been configured to support cross-compilation.

              Install a sysroot for the target platform and configure it via
              PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
              cross-compiling wrapper for pkg-config and set it via
              PKG_CONFIG environment variable.

My Cargo.toml contains (excerpt):

[target.'cfg(target_os = "android")'.dependencies]
cairo = "0.0.4"
freetype = "0.7.0"
glib = "0.14.2"
openssl = "0.10.36"
openssl-sys = {version = "0.9.66", features = ["vendored"]}

crate-type = ["staticlib", "rlib"]

I should add, what I am doing is cargo build --target aarch64-linux-android.

Looks like you will have to install a sysroot for android and then configure pkg-config to read from it.

And how do I do that?

According to Android - SDL Wiki the library has to be in the sysroot directory of the ndk installation. I think you then have to set the PKG_CONFIG_SYSROOT_DIR env var to the path to the syroot dir.

I found this guide on how to compile glib for android: Cross-compile GLib for Android ยท Nosce Te Ipsum The prefix has to either be the sysroot dir of the ndk or the usr subdirectory of sysroot I think.

If this doesn't work I don't think I can help any further. I haven't tried to set this up for myself.

OK, thanks for this. It led me to revise all the documentation on Rust, cross-platform compilation, and Android, and that has led me to restructure my crates and their dependencies. It seems that I do not need glib at all when I am building for Android (glib is for Linux PC). So I am unstuck now, I think.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.