Skip to content

Find the Android backend classes through djinni's cached class loader - #140

Merged
ethindp merged 1 commit into
ethindp:masterfrom
trypsynth:android-find-class
Sep 23, 2026
Merged

ethindp merged 1 commit into
ethindp:masterfrom
trypsynth:android-find-class

Conversation

@trypsynth

Copy link
Copy Markdown
Contributor

The Android TTS backend waits for TextToSpeech's init callback, and Android delivers that callback on the main thread. So an app has to create the backend on another thread, or it waits the full 10 seconds and gets BackendNotAvailable. On a thread that Java didn't start, JNIEnv::FindClass uses the system class loader, which can't see the app's classes. So initialize and get_features can't find AndroidTextToSpeechBackend or AndroidScreenReaderBackend there either, and every Android backend fails:

I REFRACTOR: backend Android Screen Reader
I REFRACTOR: backend Android Text to Speech
I REFRACTOR: failed Refractor.PrismException: Backend not available

What this does

The backends look up their classes with djinni::jniFindClass. It tries FindClass first, then falls back to the class loader that djinni saved in JNI_OnLoad, which djinni keeps for this exact case. jniFindClass throws when a class is missing, so initialize is now a function try block that returns BackendNotAvailable, the same as get_features.

Testing

I ran a .NET Android app on an API 34 x86_64 emulator. The app calls prism_registry_create_best from a thread pool thread. Without this change, that call returns PRISM_ERROR_BACKEND_NOT_AVAILABLE. With it, it picks Android Text to Speech, and prism_backend_speak succeeds.

@ethindp
ethindp merged commit 35efa23 into ethindp:master Sep 23, 2026
59 checks passed
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