Skip to content

Commit

Permalink
Fixing Cobalt APK JNI initialization (#4359)
Browse files Browse the repository at this point in the history
- Move JNI state variables into a standalone dynamic library to ensure
all callers obtain consistent, shared state.

- Disable POSIX emulation functions, they run into initialization order
conflicts where JNI state isn't available when functions like `close`
are already called.

- Disable problematic extensions that interact early with JNI

- Fix initialization order. Chromium library loader (
LibraryLoader.ensureInitialized ) needs to run and load all dynamic
libraries and initialize its JNI environment, before Starboard bridge
loads. It also calls `JNI_OnLoad` in `cobalt_library_loader.cc` and
passes it a VM pointer.

- Restore StarboardBridge native JNI initialization, start the Starboard
thread, and enable related minimal modules, including AudioManager and
VideoSurfaceView

- Ensure JNI_VERSION matches with what Chromium default uses (
JNI_VERSION_1_6 is only used for Cronet, but not elsewhere ).

- Ensure initial deeplink variable is never null to prevent crashing
early init, use an empty string instead.

b/376348543
  • Loading branch information
kaidokert authored Nov 4, 2024
1 parent 5c3993c commit 477c627
Show file tree
Hide file tree
Showing 14 changed files with 442 additions and 202 deletions.
4 changes: 2 additions & 2 deletions cobalt/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ android_library("cobalt_apk_java") {
"apk/app/src/main/java/dev/cobalt/coat/VolumeStateReceiver.java",
"apk/app/src/main/java/dev/cobalt/libraries/services/clientloginfo/ClientLogInfo.java",
"apk/app/src/main/java/dev/cobalt/libraries/services/clientloginfo/ClientLogInfoModule.java",

# "apk/app/src/main/java/dev/cobalt/media/AudioOutputManager.java",
"apk/app/src/main/java/dev/cobalt/media/AudioOutputManager.java",
"apk/app/src/main/java/dev/cobalt/media/AudioTrackBridge.java",
"apk/app/src/main/java/dev/cobalt/media/Log.java",
"apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java",
Expand Down Expand Up @@ -169,6 +168,7 @@ shared_library("libcobalt_content_shell_content_view") {
"//content/shell/android:content_shell_jni_headers",
"//media",
"//skia",
"//starboard/android/shared:starboard_jni_state",
]

# Explicit dependency required for JNI registration to be able to
Expand Down
1 change: 1 addition & 0 deletions cobalt/android/apk/apk_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ apk_sources = [
"//starboard/android/apk/app/src/main/java/dev/cobalt/libraries/services/clientloginfo/ClientLogInfo.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/libraries/services/clientloginfo/ClientLogInfoModule.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/AudioOutputManager.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/AudioOutputManager.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/AudioTrackBridge.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/Log.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java",
Expand Down
Loading

0 comments on commit 477c627

Please sign in to comment.