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

Droidplug has not been initialized (Android) #359

Open
JosuGZ opened this issue Dec 27, 2023 · 2 comments
Open

Droidplug has not been initialized (Android) #359

JosuGZ opened this issue Dec 27, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@JosuGZ
Copy link

JosuGZ commented Dec 27, 2023

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 JosuGZ added the bug Something isn't working label Dec 27, 2023
@JosuGZ
Copy link
Author

JosuGZ commented Dec 27, 2023

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
Copy link
Author

JosuGZ commented Dec 27, 2023

Adding this works:

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

Setting gradle is tricky though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant