Sau đây là ví dụ về cách tạo một tệp nhị phân Rust phụ thuộc vào một thư viện Rust.
Các mô-đun Rust hiện bị giới hạn trong các thư mục cụ thể được xác định trong build/soong/rust/config/allowed_list.go. Mô-đun helloWorld sau đây sử dụng thư mục external/rust để tránh sửa đổi danh sách này.
Từ thư mục gốc của AOSP
mkdir -p external/rust/hello_rust/src/mkdir -p external/rust/libsimple_printer/src/
Tạo external/rust/hello_rust/src/hello_rust.rs có nội dung sau:
use simple_printer;
fn main() {
 simple_printer::print_hello_rust();
}
Tạo tệp external/rust/libsimple_printer/src/lib.rs có nội dung sau:
pub fn print_hello_rust() {
  println!("Hello Rust!");
}
Tạo tệp external/rust/hello_rust/Android.bp có nội dung sau:
rust_binary {
    name: "hello_rust",
    // srcs must contain a single source file, the entry point source.
    srcs: ["src/hello_rust.rs"],
    // rustlibs are Rust library dependencies. The type, rlib (static) or dylib
    // (dynamic), are chosen automatically based on module type and target
    // to avoid linkage issues.
    rustlibs: ["libsimple_printer"],
    // define any additional compilation flags
    flags: [
        "-C debug-assertions=yes",
    ],
    // cc libraries can be linked in to rust binaries and libraries through the
    // shared_libs and static_libs properties. These are not needed for this
    // simple example, so they are not included.
}
Tạo tệp external/rust/libsimple_printer/Android.bp có nội dung sau:
// rust_library provides dylib and rlib variants.
rust_library {
    //name or stem properties must be of the form lib<crate_name><any_suffix>
    name: "libsimple_printer",
    //crate_name must match the name used in source (e.g. extern crate <name>)
    crate_name: "simple_printer",
    //srcs must contain a single source file, the entry point source
    srcs: ["src/lib.rs"],
}
Cuối cùng, hãy tạo mô-đun hello_rust:
source build/envsetup.shlunch aosp_arm64-engm hello_rust