LIBC for Android Ecosystem

I have my Android.bp file (while building a rust_ffi) defined as:

rust_ffi {
name: "libShared",
vendor_available: true,
crate_name: "Shared",
srcs: [""],
rustlibs: ["libc",],
include_dirs: ["."],

The error message while building:
a. missing dependencies: libc{os:android,image:vendor.31,arch:arm_armv8-a_cortex-a76,sdk:,rust_libraries:dylib}"
b. missing dependencies: libc{os:android,image:vendor.31,arch:arm_armv8-a_cortex-a76,sdk:,rust_libraries:rlib,rust_stdlinkage:rlib-std}"

How can I fix this? My motive is to use functios of "libc" library in my rust code.

Edit: it looks like I was wrong, please read the other answers

Old answer

That's not possible. Libc is provided by the GNU operating system (GNU/Linux), and while Android is based on the Linux kernel, it is its own operating system.

As far as I know, you'll have to use the interfaces provided by the Android NDK, depending on what exactly you are trying to do. The cleanest would be to do all the IO stuff from Java and just use your Rust code as an isolated worker only. Without more context, I won't be able to provide more help.

1 Like

The libc crate does support Android, and those functions are provided in the bionic implementation in the Android NDK. You can find target-specific documentation here:

I don't know the specifics of dealing with Android.bp though.

1 Like

I think the simplest way would be to look on some other crate which depends on libc. E.g. mio.

It looks as if you have to use name "liblibc" for that crate. That's because libc's Android.bp specifies that rust library name (but "crate name" is still "lib").

As for why they are doing this… I suspect that's because "libc" library name is taken. By bionic. Thus they needed some different name for rust one.

1 Like

We prefix all Rust crates with lib.

Ah. And then suffix is added if there are still conflicts. Makes sense.