Skip to content

Instantly share code, notes, and snippets.

@Kudo
Last active September 5, 2023 10:16
Show Gist options
  • Save Kudo/cc40662163fbd69dd01d66fd99476c17 to your computer and use it in GitHub Desktop.
Save Kudo/cc40662163fbd69dd01d66fd99476c17 to your computer and use it in GitHub Desktop.
Steps to integrate experimented JSC

Intro

Here are the steps to integrate experimented JavaScriptCore. Hopefully this could solve the JSC crash issue on RN 0.59.

Steps (for RN 0.59)

  1. yarn add 'jsc-android@next'
  2. Modify build.gradle files.
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 67980c5..0bc0510 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -135,9 +135,16 @@ android {
             }
         }
     }
+
+    packagingOptions {
+        pickFirst '**/libjsc.so'
+    }
 }

 dependencies {
+    // Make sure to put android-jsc at the the first
+    implementation "org.webkit:android-jsc:r241213"
+
     implementation fileTree(dir: "libs", include: ["*.jar"])
     implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
     implementation "com.facebook.react:react-native:+"  // From node_modules
diff --git a/android/build.gradle b/android/build.gradle
index c6e7c7c..bd847fa 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -29,5 +29,9 @@ allprojects {
             // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
             url "$rootDir/../node_modules/react-native/android"
         }
+        maven {
+            // Local Maven repo containing AARs with JSC library built for Android
+            url "$rootDir/../node_modules/jsc-android/dist"
+        }
     }
 }
  1. Open a terminal shell to execute.

adb logcat | grep JavaScriptCore.Version

This step is to double confirm if you pick the right JSC version. As gradle's packagingOptions.pickFirst is not reliable to pick expected library.

  1. react-native run-android or gradle rebuild.

  2. The previous adb logcat result should be somehow like 05-17 21:09:07.352 14710 16259 D JavaScriptCore.Version: 241213.9000.0 The version should be 241213.9000.0

  3. Check if crash happens.

Feedback

Please feedbeck to me if these experimented versions fix the crash issue or not. On the other hand, the overall performance & TTI (App launch Time-To-Interact) is also meaningful to me. I want some real world feedback if there are impact to turn off JIT.

If crash still happens.

Please provide the backtrace to me.

wget https://registry.npmjs.org/jsc-android/-/jsc-android-241213.2.0.tgz
tar xf jsc-android-241213.2.0.tgz
unzip package/dist/org/webkit/android-jsc/r241213/android-jsc-r241213.aar

adb logcat -c
adb logcat | ndk-stack -sym jni/arm64-v8a/libjsc.so

Intro

Here are the steps to integrate experimented JavaScriptCore. Hopefully this could solve the JSC crash issue on RN 0.59.

Steps (for RN 0.59)

  1. yarn add 'jsc-android@next'
  2. Modify build.gradle files.
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 67980c5..0bc0510 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -135,9 +135,16 @@ android {
             }
         }
     }
+
+    packagingOptions {
+        pickFirst '**/libjsc.so'
+    }
 }

 dependencies {
+    // Make sure to put android-jsc at the the first
+    implementation "org.webkit:android-jsc:r245459"
+
     implementation fileTree(dir: "libs", include: ["*.jar"])
     implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
     implementation "com.facebook.react:react-native:+"  // From node_modules
diff --git a/android/build.gradle b/android/build.gradle
index c6e7c7c..bd847fa 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -29,5 +29,9 @@ allprojects {
             // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
             url "$rootDir/../node_modules/react-native/android"
         }
+        maven {
+            // Local Maven repo containing AARs with JSC library built for Android
+            url "$rootDir/../node_modules/jsc-android/dist"
+        }
     }
 }
  1. Open a terminal shell to execute.

adb logcat | grep JavaScriptCore.Version

This step is to double confirm if you pick the right JSC version. As gradle's packagingOptions.pickFirst is not reliable to pick expected library.

  1. react-native run-android or gradle rebuild.

  2. The previous adb logcat result should be somehow like 05-17 21:09:07.352 14710 16259 D JavaScriptCore.Version: 245459.0.0 The version should be 245459.0.0

  3. Check if crash happens.

Feedback

Please feedbeck to me if these experimented versions fix the crash issue or not. On the other hand, the overall performance & TTI (App launch Time-To-Interact) is also meaningful to me. I want some real world feedback if there are impact to turn off JIT.

If crash still happens.

Please provide the backtrace to me.

wget https://registry.npmjs.org/jsc-android/-/jsc-android-245459.0.0.tgz
tar xf jsc-android-245459.0.0.tgz
unzip package/dist/org/webkit/android-jsc/r245459/android-jsc-r245459.aar

adb logcat -c
adb logcat | ndk-stack -sym jni/arm64-v8a/libjsc.so
@yurapav99
Copy link

yurapav99 commented Jun 24, 2019

@Kudo thank you very much, but there is one moment,
I use: "compile "org.webkit:android-jsc:r245459"" instead of "implementation "org.webkit:android-jsc:r245459"".
The reason is, that it doesn't triggered my JavaScriptCore.Version.

@ollyde
Copy link

ollyde commented Aug 12, 2019

Could not find org.webkit:android-jsc:r241213.

@trungtran0689
Copy link

@Kudo thank you very much, it saves my life

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