Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndk-examples: Update jni dependency to 0.20 #366

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ndk-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
publish = false

[target.'cfg(target_os = "android")'.dependencies]
jni = "0.19"
jni = "0.20"
libc = "0.2"
log = "0.4.14"
ndk = { path = "../ndk", features = ["api-level-23"] }
Expand Down
9 changes: 6 additions & 3 deletions ndk-examples/examples/jni_audio.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use jni::objects::JObject;

#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))]
fn main() {
enumerate_audio_devices().unwrap();
Expand All @@ -9,6 +11,7 @@ fn enumerate_audio_devices() -> Result<(), Box<dyn std::error::Error>> {
// Create a VM for executing Java calls
let ctx = ndk_context::android_context();
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
let context = unsafe { JObject::from_raw(ctx.context().cast()) };
let env = vm.attach_current_thread()?;

// Query the global Audio Service
Expand All @@ -17,7 +20,7 @@ fn enumerate_audio_devices() -> Result<(), Box<dyn std::error::Error>> {

let audio_manager = env
.call_method(
ctx.context().cast(),
context,
"getSystemService",
// JNI type signature needs to be derived from the Java API
// (ArgTys)ResultTy
Expand All @@ -36,7 +39,7 @@ fn enumerate_audio_devices() -> Result<(), Box<dyn std::error::Error>> {

println!("-- Output Audio Devices --");

let device_array = devices.l()?.into_inner();
let device_array = devices.l()?.into_raw();
let len = env.get_array_length(device_array)?;
for i in 0..len {
let device = env.get_object_array_element(device_array, i)?;
Expand All @@ -56,7 +59,7 @@ fn enumerate_audio_devices() -> Result<(), Box<dyn std::error::Error>> {
let sample_array = env
.call_method(device, "getSampleRates", "()[I", &[])?
.l()?
.into_inner();
.into_raw();
let len = env.get_array_length(sample_array)?;

let mut sample_rates = vec![0; len as usize];
Expand Down