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
@RomanovYurii
Copy link

Your soultion didn't help at all, causing crashes all the time. This one helped

@ouabing
Copy link

ouabing commented Jun 3, 2019

@RomanovYurii You are just disabling building 64bit apk. Crashs only happened when 64bit enabled.

@Kudo
Copy link
Author

Kudo commented Jun 4, 2019

Since the no-jit version was merged into jsc-android upstream, update the gist to use jsc-android@next.

@RomanovYurii
Copy link

@Kudo thank you really much, I've removed my incomplete solution and used just yours and it fixed our problem on the project.

@manuhook
Copy link

manuhook commented Jun 6, 2019

@Kudo thanks a lot for your work !

I've push your solution on 250K mobiles.
No more "signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)" errors. Not a single one.
Note I was having also those errors on RN57.x / 32 bits app but much more on RN59.x 64 bits app

About performance, I didn't notice anything slower, even on low-end devices, and no complains from our users until now.

@SebDuf
Copy link

SebDuf commented Jun 6, 2019

Thank you for this, it seems to have fixed the problems we were encountering.

@wangghon
Copy link

wangghon commented Jun 13, 2019

We followed the steps above, when we run the command adb logcat | grep JavaScriptCore.Version, it still shows "06-13 15:49:26.161 17036 17057 D JavaScriptCore.Version: 236355.1.0", then the app still crashes.

The component in our package.json is "jsc-android": "^241213.2.0".

we find the reason why always the old jsc version shows up.
we should exactly follow the steps to put "implementation "org.webkit:android-jsc:r241213"" at the beginning of dependencies

@AlexeyNovikov
Copy link

Yeah, this works well for us too.

@wmonecke
Copy link

wmonecke commented Jun 23, 2019

Getting the following build error from the FBSDK:

Task :react-native-fbsdk:compileReleaseJavaWithJavac FAILED
/Users/waltermonecke/Documents/Code/React-Native2/moodPixel/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBAppEventsLoggerMod
ule.java:209: error: cannot find symbol
     @ReactMethod(isBlockingSynchronousMethod = true)
                                                ^
  symbol:   method isBlockingSynchronousMethod()
  location: @interface ReactMethod
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/waltermonecke/Documents/Code/React-Native2/moodPixel/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/Utility.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

FAILURE: Build failed with an exception.

"react-native-fbsdk": "^0.8.0",

Any ideas?

@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