btleplug icon indicating copy to clipboard operation
btleplug copied to clipboard

Droidplug has not been initialized (Android)

Open JosuGZ opened this issue 2 years ago • 3 comments

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 avatar Dec 27 '23 19:12 JosuGZ

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 avatar Dec 27 '23 21:12 JosuGZ

Adding this works:

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

Setting gradle is tricky though.

JosuGZ avatar Dec 27 '23 22:12 JosuGZ