You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

jsc-android

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsc-android

Pre-build version of JavaScriptCore to be used by React Native apps


Version published
Weekly downloads
1.9M
increased by2.27%
Maintainers
1
Install size
15.5 MB
Created
Weekly downloads
 

Package description

What is jsc-android?

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.

What are jsc-android's main functionalities?

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"

Other packages similar to jsc-android

Readme

Source

JSC build scripts for Android

The aim of this project is to provide maintainable build scripts for the JavaScriptCore JavaScript engine and allow the React Native community 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).

Requirements

There is a huge list of requirements that need to be installed on your system in order to be able to cross-compile JSC for Android. To simplify the process of setting up the environment we provide a Docker image that comes with everything you will need. If you decide to use our Docker image, the only thing you need to do is to prefix each command with this:

docker run -v `pwd`:/bitrise/src --rm swmansion/jsc-android-buildscripts
Example:
docker run -v `pwd`:/bitrise/src --rm swmansion/jsc-android-buildscripts ./fetch_sources.sh
Don't want to use Docker

As mentioned the list of dependencies is huge, we tried to list everything that is needed below:

  • Android SDK & NDK
  • Ruby (2.3), Python (2.7), Node (7.x), Git, SVN, gperf
  • CMake installed via Android SDK manager

Build instructions

IMPORTANT: Remember to prefix each command with the appropriate Docker command given above when using our Docker image

  1. git clone https://github.com/SoftwareMansion/jsc-android-buildscripts.git .
  2. ./fetch_sources.sh
  3. ./icu-prep.sh
  4. ./jsc-prep.sh
  5. ./all.sh
  6. ./gradlew installArchives (add -w /bitrise/src/lib to docker run args)

The Maven repo containing the android-jsc AAR will be available at ./lib/android.

Distribution

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.

How to use it with my React Native app

Follow steps below in order for your React Native app to use new version of JSC VM on android:

  1. Add jsc-android to the "dependencies" section in your package.json:
dependencies {
+  "jsc-android": "^216113.0.0-beta.5",

then run npm install or yarn (depending which npm client you use) in order for the new dependency to be installed in node_modules

  1. Modify andorid/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/android"
+       }
    }
}
  1. Update your app's 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:r216113'
+    }
+}

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
  1. You're done, rebuild your app and enjoy updated version of JSC on android!

How to use it with React Native

We will be working on updating React Native to use a new version of JSC. Once that gets approved the only thing you will need to do is to update your RN version!

Testing

As a part of this project we provide a patch to the React Native source code that allows for measuring a React Native application's cold-start time. The methodology behind this test is to modify the part of the code that is responsible for loading JS bundles into the JS VM such that we measure and store the execution time, and to modify the process of instantiating the bridge so we can run it multiple times. To learn more about how the perf tests work and how to perform them, refer to this document. Results for the Samsung Galaxy S4 are presented below:

android-jsc (r174650)new JSC (r216113)
cold start time427 ms? ms
binary size (armv7)1.8 MiB4.4 MiB
binary size (x86)4.4 MiB7.5 MiB
binary size (arm64)N/A6.7 MiB
binary size (x86_64)N/A7.4 MiB

Credits

This project has been built in cooperation between Expo.io and Software Mansion

expo swm

Keywords

FAQs

Package last updated on 27 Jun 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc