Repository navigation
Find the Android backend classes through djinni's cached class loader - #140
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 getsBackendNotAvailable. On a thread that Java didn't start,JNIEnv::FindClassuses the system class loader, which can't see the app's classes. Soinitializeandget_featurescan't findAndroidTextToSpeechBackendorAndroidScreenReaderBackendthere either, and every Android backend fails:What this does
The backends look up their classes with
djinni::jniFindClass. It triesFindClassfirst, then falls back to the class loader that djinni saved inJNI_OnLoad, which djinni keeps for this exact case.jniFindClassthrows when a class is missing, soinitializeis now a function try block that returnsBackendNotAvailable, the same asget_features.Testing
I ran a .NET Android app on an API 34 x86_64 emulator. The app calls
prism_registry_create_bestfrom a thread pool thread. Without this change, that call returnsPRISM_ERROR_BACKEND_NOT_AVAILABLE. With it, it picks Android Text to Speech, andprism_backend_speaksucceeds.