src/android/build-rules/library.md
You use rust_library to create a new Rust library for Android.
Here we declare a dependency on two libraries:
libgreeting, which we define below,libtextwrap, which is a crate already vendored in
external/rust/android-crates-io/crates/.hello_rust/Android.bp:
{{#include library/Android.bp}}
hello_rust/src/main.rs:
# // Copyright 2022 Google LLC
# // SPDX-License-Identifier: Apache-2.0
#
{{#include library/src/main.rs:main}}
hello_rust/src/lib.rs:
# // Copyright 2022 Google LLC
# // SPDX-License-Identifier: Apache-2.0
#
{{#include library/src/lib.rs:greeting}}
You build, push, and run the binary like before:
{{#include ../build_all.sh:hello_rust_with_dep}}
Hello Bob, it is very
nice to meet you!
Go through the build steps and demonstrate them running in your emulator.
A Rust crate named greetings must be built by a rule called libgreetings.
Note how the Rust code uses the crate name, as is normal in Rust.
Again, the build rules enforce that we add documentation comments to all public items.