deviceplug / btleplug

Rust Cross-Platform Host-Side Bluetooth LE Access Library
Other
814 stars 150 forks source link

Droidplug has not been initialized (Android) #359

Open JosuGZ opened 10 months ago

JosuGZ commented 10 months ago

I'm getting this problem when running on Android: "Droidplug has not been initialized. Please initialize it with btleplug::platform::init().".

Should I have to call this myself? If that is the case an example on the README would be nice, although perhaps the problem is on how I'm (trying) to add the Java code to the project.

JosuGZ commented 10 months ago

Ok, I made some progress, it seems that given mut env: JNIEnv<'local> I can add this (as long as I use the same version of the jni crate...):

#[cfg(target_os = "android")]
btleplug::platform::init(&env);

Now I'm getting this, which probably means I'm not loading the Java libraries properly...

JNI DETECTED ERROR IN APPLICATION: JNI NewStringUTF called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.nonpolynomial.btleplug.android.impl.Adapter"
JosuGZ commented 10 months ago

Adding this works:

#[cfg(target_os = "android")]
btleplug::platform::init(&env);

Setting gradle is tricky though.