feat: add basic rust JNI demo
This commit is contained in:
parent
954d100742
commit
8d1472b5a7
6 changed files with 61 additions and 0 deletions
20
rust-sandbox/.gitignore
vendored
Normal file
20
rust-sandbox/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Created by https://www.toptal.com/developers/gitignore/api/rust
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=rust
|
||||
|
||||
### Rust ###
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/rust
|
||||
13
rust-sandbox/Cargo.toml
Normal file
13
rust-sandbox/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "rust-sandbox"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "rustsandbox"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
jni = "0.21.1"
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
15
rust-sandbox/src/lib.rs
Normal file
15
rust-sandbox/src/lib.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use jni::{
|
||||
objects::{JClass, JObject},
|
||||
JNIEnv,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_net_mbess_popequer_Native_add(
|
||||
_env: JNIEnv,
|
||||
_class: JClass,
|
||||
a: i32,
|
||||
b: i32
|
||||
) -> i32 {
|
||||
a + b
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue