|
1 | | -# `android-ndk`: Rust bindings of the Android NDK |
| 1 | +# Rust on Android |
2 | 2 |
|
3 | | -[](https://travis-ci.org/mb64/android-ndk-rs) |
4 | | -[](https://crates.io/crates/android-ndk-sys) |
5 | | -[](https://docs.rs/android-ndk-sys) |
6 | | -[](https://crates.io/crates/android-ndk) |
7 | | -[](https://docs.rs/android-ndk) |
| 3 | + - Raw FFI bindings to the NDK ![ndk-sys-docs][ndk-sys-badge] |
| 4 | + - Safe abstraction of the bindings ![ndk-docs][ndk-badge] |
| 5 | + - Startup code ![ndk-glue-docs][ndk-glue-badge] |
| 6 | + - Everything for building apk's ![ndk-build-docs][ndk-build-badge] |
| 7 | + - Build tool ![cargo-apk-docs][cargo-apk-badge] |
8 | 8 |
|
9 | | -This is a work in progress at the moment. |
| 9 | +## Hello world |
| 10 | +`Cargo.toml` |
| 11 | +```toml |
| 12 | +[lib] |
| 13 | +crate-type = ["lib", "cdylib"] |
| 14 | +``` |
10 | 15 |
|
11 | | -`android-ndk-sys` contains the raw FFI bindings, pre-generated from NDK r20, and `android-ndk` |
12 | | -provides a safe API over it. |
| 16 | +`src/lib.rs` |
| 17 | +```rust |
| 18 | +#[cfg(target_os = "android")] |
| 19 | +ndk_glue::ndk_glue!(main); |
13 | 20 |
|
14 | | -Other helpful crates for Android: |
| 21 | +pub fn main() { |
| 22 | + println!("hello world"); |
| 23 | +} |
| 24 | +``` |
15 | 25 |
|
16 | | - * [`jni`](https://crates.io/crates/jni), JNI bindings for Rust |
17 | | - * [`android_logger`](https://crates.io/crates/android_logger) and [`ndk-logger`](https://crates.io/crates/ndk-logger), |
18 | | - Android backends for the `log` crate |
| 26 | +`src/main.rs` |
| 27 | +```rust |
| 28 | +fn main() { |
| 29 | + $crate::main(); |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +```sh |
| 34 | +cargo install cargo-apk |
| 35 | +cargo apk run |
| 36 | +``` |
| 37 | + |
| 38 | +## Logging and stdout |
| 39 | +Stdout is redirected to the android log api when using `ndk-glue`. Any logger that logs to |
| 40 | +stdout should therefore work. |
| 41 | + |
| 42 | +## JNI |
| 43 | +TODO: talk more about jni and add some examples |
| 44 | + |
| 45 | +- [`jni`](https://crates.io/crates/jni), JNI bindings for Rust |
| 46 | + |
| 47 | +## Winit and glutin |
| 48 | +TODO shameless plug |
| 49 | + |
| 50 | +## Flutter |
| 51 | +TODO shameless plug |
| 52 | + |
| 53 | +[ndk-sys-docs]: https://docs.rs/ndk-sys |
| 54 | +[ndk-sys-badge]: https://docs.rs/ndk-sys/badge.svg |
| 55 | +[ndk-docs]: https://docs.rs/ndk |
| 56 | +[ndk-badge]: https://docs.rs/ndk/badge.svg |
| 57 | +[ndk-glue-docs]: https://docs.rs/ndk-glue |
| 58 | +[ndk-badge]: https://docs.rs/ndk-glue/badge.svg |
| 59 | +[ndk-build-docs]: https://docs.rs/ndk-build |
| 60 | +[ndk-build-badge]: https://docs.rs/ndk-build/badge.svg |
| 61 | +[cargo-apk-docs]: https://docs.rs/cargo-apk |
| 62 | +[cargo-apk-badge]: https://docs.rs/cargo-apk/badge.svg |
0 commit comments