Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
jsc-android
Advanced tools
Pre-build version of JavaScriptCore to be used by React Native apps
The jsc-android package provides an optimized version of the JavaScriptCore engine for Android. This allows developers to leverage the latest JavaScript features and improvements in performance within their React Native applications or any other Android project that requires an embedded JavaScript engine.
Using modern JavaScript features in Android apps
This code demonstrates how to use jsc-android to run JavaScript code, utilizing modern JavaScript features, directly within an Android application. It creates a new JavaScript context and evaluates a simple script.
"import org.liquidplayer.javascript.JSContext;\n\npublic class MainActivity extends AppCompatActivity {\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n\n JSContext context = new JSContext();\n context.evaluateScript(\"'Hello, World!'.toUpperCase();\");\n }\n}"
Improving React Native performance
By including jsc-android in a React Native project's dependencies, developers can improve the performance of their applications. This is particularly beneficial for complex applications that require a lot of JavaScript execution.
"dependencies {\n implementation 'org.webkit:android-jsc:r250230'\n}\n"
Similar to jsc-android, v8-android provides the V8 JavaScript engine for Android applications. While jsc-android uses the JavaScriptCore engine, v8-android uses Google's V8 engine. This difference in the underlying engine can lead to variations in performance and compatibility with JavaScript features.
Hermes is a JavaScript engine optimized for running React Native on Android. It aims to improve startup time, decrease memory usage, and increase overall performance. Unlike jsc-android, Hermes is built specifically for React Native and may offer better optimizations for React Native apps.
The aim of this project is to provide maintainable build scripts for the JavaScriptCore JavaScript engine and allow the React Native project to incorporate up-to-date releases of JSC into the framework on Android.
This project is based on facebook/android-jsc but instead of rewriting JSC's build scripts into BUCK files, it relies on CMake build scripts maintained in a GTK branch of WebKit maintained by the WebKitGTK team (great work btw!). Thanks to that, with just a small amount of work we should be able to build not only current but also future releases of JSC. An obvious benefit for everyone using React Native is that this will allow us to update JSC for React Native on Android much more often than before (note that facebook/android-jsc uses JSC version from Nov 2014), which is especially helpful since React Native on iOS uses the built-in copy of JSC that is updated with each major iOS release (see this as a reference).
brew install coreutils
brew install node
brew tap caskroom/versions && brew cask install java8
brew cask install android-sdk
sdkmanager --list
and install all platforms, tools, buildtool v28.0.3, cmake (android images are not needed)$ANDROID_HOME
to the correct path (in ~/.bashrc or similar)export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools/bin
export ANDROID_NDK=/path/to/android-ndk-r19c
npm run clean
will clean everything (artifacts, downloaded sources)package.json
to the desired build configurationprintVersion
patch in jsc.patch)npm run download
: downloads all needed sourcesnpm run start
: builds jsc (this might take some time...)The zipfile containing the android-jsc AAR will be available at /dist
.
The library is packaged as a local Maven repository containing AAR files that include the binaries.
JSC library built using this project is distributed over npm: npm/jsc-android. The library is packaged as a local Maven repository containing AAR files that include the binaries. Please refer to the section below in order to learn how your app can consume this format.
On load, JSC prints the version out to logcat, under "JavaScriptCore.Version" tag.
Follow steps below in order for your React Native app to use new version of JSC VM on android:
jsc-android
:yarn add jsc-android
# Or if you would like to try latest version
# yarn add 'jsc-android@next'
jsc-android
:yarn add jsc-android
# Or if you would like to try latest version
# yarn add 'jsc-android@next'
android/build.gradle
file to add the new local maven repository packaged in the jsc-android
package to the search path:allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// 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"
+ }
}
}
build.gradle
file located in android/app/build.gradle
to add the JSC dependency. Please make sure the dependency is before the React Native dependency.
dependencies {
+ // Make sure to put android-jsc at the top
+ implementation "org.webkit:android-jsc:+"
+
compile fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
}
build.gradle
file located in android/app/build.gradle
to use first matched JSC library.android {
// ...
+ packagingOptions {
+ pickFirst '**/libjsc.so'
+ pickFirst '**/libc++_shared.so'
+ }
}
jsc-android
:yarn add jsc-android
# Or if you would like to try latest version
# yarn add 'jsc-android@next'
android/build.gradle
file to add new local maven repository packaged in the jsc-android
package to the search path:allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// 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"
+ }
}
}
build.gradle
file located in android/app/build.gradle
to force app builds to use new version of the JSC library as opposed to the version specified in react-native gradle module as a dependency:}
+configurations.all {
+ resolutionStrategy {
+ force 'org.webkit:android-jsc:+'
+ }
+}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
+ // ...
+ implementation 'org.webkit:android-jsc-cppruntime:+'
+ // For even older gradle
+ // compile 'org.webkit:android-jsc-cppruntime:+'
International variant includes ICU i18n library and necessary data allowing to use e.g. Date.toLocaleString and String.localeCompare that give correct results when using with locales other than en-US. Note that this variant is about 6MiB larger per architecture than default.
To use this variant instead replace the third installation step with:
For React Native version 0.60 and newer, your build.gradle should have a flag to enable this feature.
/**
* Use the international variant of JavaScriptCore
* This variant includes the ICU i18n library to make APIs like `Date.toLocaleString`
* and `String.localeCompare` work when using with locales other than en-US.
* Note that this variant is about 6MiB larger per architecture than the default.
*/
- def useIntlJsc = false
+ def useIntlJsc = true
For React Native version 0.59, replace original artifact id with android-jsc-intl
dependencies {
+ // Make sure to put android-jsc at the the first
+ implementation "org.webkit:android-jsc-intl:+"
+
compile fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
}
For React Native version 0.58 below, replace original resolutionStrategy
with this.
+configurations.all {
+ resolutionStrategy {
+ eachDependency { DependencyResolveDetails details ->
+ if (details.requested.name == 'android-jsc') {
+ details.useTarget group: details.requested.group, name: 'android-jsc-intl', version: 'r241213'
+ }
+ }
+ }
+}
See Measurements page that contains synthetic perf test results for the most notable versions of JSC we have tried.
Compile errors of the sort:
More than one file was found with OS independent path 'lib/armeabi-v7a/libgnustl_shared.so'
Add the following to your app/build.gradle
, under android
:
packagingOptions {
pickFirst '**/libgnustl_shared.so'
}
Check the list of contributors here. This project is supported by:
FAQs
Pre-build version of JavaScriptCore to be used by React Native apps
The npm package jsc-android receives a total of 1,668,041 weekly downloads. As such, jsc-android popularity was classified as popular.
We found that jsc-android demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.