Kaiser1989 / android-ndk-rs

Rust bindings to the Android NDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rust on Android

  • Raw FFI bindings to the NDK ndk-sys-docs
  • Safe abstraction of the bindings ndk-docs
  • Startup code ndk-glue-docs
  • Everything for building apk's ndk-build-docs
  • Build tool cargo-apk-docs

Hello world

Cargo.toml

[lib]
crate-type = ["lib", "cdylib"]

Wraps main function using attribute macro ndk::glue::main:

src/lib.rs

#[cfg_attr(target_os = "android", ndk_glue::main(backtrace))]
pub fn main() {
    println!("hello world");
}

src/main.rs

fn main() {
    $crate::main();
}
cargo install cargo-apk
cargo apk run

Logging and stdout

Stdout is redirected to the android log api when using ndk-glue. Any logger that logs to stdout should therefore work.

Android logger

Android logger can be setup using feature "logger" and attribute macro like so:

src/lib.rs

#[cfg_attr(target_os = "android", ndk_glue::main(logger(debug, "my-tag")))]
pub fn main() {
    println!("hello world");
}

JNI

TODO: talk more about jni and add some examples

  • jni, JNI bindings for Rust

Winit and glutin

TODO shameless plug

Flutter

TODO shameless plug

About

Rust bindings to the Android NDK

License:Apache License 2.0


Languages

Language:Rust 99.9%Language:C++ 0.0%Language:Shell 0.0%