Skip to content

fix(droidplug): Resolve Adapter through LoaderContext in init - #495

Open
LucaCappelletti94 wants to merge 1 commit into
deviceplug:masterfrom
LucaCappelletti94:upstream/android-init-loader-context
Open

LucaCappelletti94 wants to merge 1 commit into
deviceplug:masterfrom
LucaCappelletti94:upstream/android-init-loader-context

Conversation

@LucaCappelletti94

Copy link
Copy Markdown

init looked up Adapter with plain FindClass, while every other class went through LoaderContext. On a thread attached from native code, Android's FindClass searches only the system class loader (JNI tips), so init failed with ClassNotFoundException there even when the thread's context class loader was the application's. Dioxus's manganis (0.7.4 and later) gets the JavaVM from ndk_context and attaches the calling thread itself (activity.rs).

#311 hit the same system class loader failure for FutureException.

Adapter now resolves through the same LoaderContext, which tries the context class loader before FindClass. The Android test app now calls init from a thread it attaches itself, which covers this path in place of the Java-thread one, since init runs once per process.

On a Galaxy M52 (Android 13) and two Galaxy A35s (Android 14 and 15), the test app's setup fails with failed to resolve Java class 'com/nonpolynomial/btleplug/android/impl/Adapter' before this change, and testAdapterAddress passes after it.

@qdot

qdot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

If this ends up fixing my Galaxy issues on my other software, I owe you greatly. :)

@LucaCappelletti94

Copy link
Copy Markdown
Author

Lmk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants