{"id":13721301,"url":"https://github.com/Kudo/react-native-v8","last_synced_at":"2025-05-07T13:32:11.963Z","repository":{"id":37698052,"uuid":"191597065","full_name":"Kudo/react-native-v8","owner":"Kudo","description":"Opt-in V8 runtime for React Native Android","archived":false,"fork":false,"pushed_at":"2024-08-20T18:29:36.000Z","size":941,"stargazers_count":925,"open_issues_count":40,"forks_count":69,"subscribers_count":18,"default_branch":"main","last_synced_at":"2024-11-12T22:02:47.716Z","etag":null,"topics":["react-native","v8"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kudo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-12T15:24:16.000Z","updated_at":"2024-11-06T23:33:32.000Z","dependencies_parsed_at":"2024-06-16T09:45:36.275Z","dependency_job_id":"5686062c-f131-4a6d-b063-408763e9869c","html_url":"https://github.com/Kudo/react-native-v8","commit_stats":{"total_commits":203,"total_committers":14,"mean_commits":14.5,"dds":0.0788177339901478,"last_synced_commit":"ad46dfd8aeaed5f181553c6d24ae82a0826774a1"},"previous_names":[],"tags_count":86,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kudo%2Freact-native-v8","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kudo%2Freact-native-v8/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kudo%2Freact-native-v8/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kudo%2Freact-native-v8/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kudo","download_url":"https://codeload.github.com/Kudo/react-native-v8/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224604865,"owners_count":17339221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react-native","v8"],"created_at":"2024-08-03T01:01:15.170Z","updated_at":"2024-11-14T10:31:20.252Z","avatar_url":"https://github.com/Kudo.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/react-native-v8.svg)](https://badge.fury.io/js/react-native-v8)\n[![Build for Android](https://github.com/Kudo/react-native-v8/actions/workflows/android.yml/badge.svg)](https://github.com/Kudo/react-native-v8/actions/workflows/android.yml)\n\n# React Native with V8 Runtime\n\nThis project aims to support V8 replacement runtime for React Native. Designed as opt-in package, it is easy to integrate with existing React Native projects.\n\n\u003e **Note** From react-native-v8 2.0, the minimum requirement for react-native is 0.71.2.\n\nFor earlier versions, please check out the older readmes.\n\n- [react-native\u003e=0.66.0 readme](https://github.com/Kudo/react-native-v8/blob/1.0-stable/README.md)\n- [react-native\u003c0.66.0 readme](https://github.com/Kudo/react-native-v8/blob/0.67-stable/README.md)\n\n## Installation for Expo projects (\u003e= SDK 48)\n\nFor managed projects, you can install through the single command:\n\n```sh\n$ npx expo install react-native-v8 v8-android-jit\n```\n\n- Please make sure you have [`\"android.jsEngine\": \"jsc\"`](https://docs.expo.dev/versions/latest/config/app/#jsengine-2).\n\nFor bare projects, you can run `npx expo prebuild -p android --clean` after the installation to prebuild again.\n\n## Installation for React Native \u003e= 0.71\n\n1. Install `react-native-v8` and a [v8-android variant](#v8-variants). For example, the `v8-android-jit`:\n\n```sh\n$ yarn add react-native-v8 v8-android-jit\n```\n\n2. Exclude unused libraries to reduce APK size\n\n```diff\n--- a/android/app/build.gradle\n+++ b/android/app/build.gradle\n@@ -161,11 +161,18 @@ android {\n             }\n         }\n     }\n+\n+    packagingOptions {\n+        // Make sure libjsc.so does not packed in APK\n+        exclude \"**/libjsc.so\"\n+    }\n }\n```\n\n3. Setup V8 in the `MainApplication.java`.\n\n```diff\n--- a/android/app/src/main/java/com/rn071/MainApplication.java\n+++ b/android/app/src/main/java/com/rn071/MainApplication.java\n@@ -1,15 +1,20 @@\n package com.rn071;\n\n import android.app.Application;\n+\n import com.facebook.react.PackageList;\n import com.facebook.react.ReactApplication;\n import com.facebook.react.ReactNativeHost;\n import com.facebook.react.ReactPackage;\n+import com.facebook.react.bridge.JavaScriptExecutorFactory;\n import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;\n import com.facebook.react.defaults.DefaultReactNativeHost;\n+import com.facebook.react.modules.systeminfo.AndroidInfoHelpers;\n import com.facebook.soloader.SoLoader;\n import java.util.List;\n\n+import io.csie.kudo.reactnative.v8.executor.V8ExecutorFactory;\n+\n public class MainApplication extends Application implements ReactApplication {\n\n   private final ReactNativeHost mReactNativeHost =\n@@ -42,6 +47,15 @@ public class MainApplication extends Application implements ReactApplication {\n         protected Boolean isHermesEnabled() {\n           return BuildConfig.IS_HERMES_ENABLED;\n         }\n+\n+        @Override\n+        protected JavaScriptExecutorFactory getJavaScriptExecutorFactory() {\n+          return new V8ExecutorFactory(\n+              getApplicationContext(),\n+              getPackageName(),\n+              AndroidInfoHelpers.getFriendlyDeviceName(),\n+              getUseDeveloperSupport());\n+        }\n       };\n\n   @Override\n```\n\nFor React Native 0.73 and above, you can use the following code instead:\n\n```diff\n--- a/android/app/src/main/java/com/rn073/MainApplication.kt\n+++ b/android/app/src/main/java/com/rn073/MainApplication.kt\n@@ -1,15 +1,20 @@\n package com.rn073;\n\n import android.app.Application\n+\n import com.facebook.react.PackageList\n import com.facebook.react.ReactApplication\n import com.facebook.react.ReactHost\n import com.facebook.react.ReactNativeHost\n import com.facebook.react.ReactPackage\n+import com.facebook.react.bridge.JavaScriptExecutorFactory\n import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load\n import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost\n import com.facebook.react.defaults.DefaultReactNativeHost\n import com.facebook.react.flipper.ReactNativeFlipper\n+import com.facebook.react.modules.systeminfo.AndroidInfoHelpers\n import com.facebook.soloader.SoLoader\n\n+import io.csie.kudo.reactnative.v8.executor.V8ExecutorFactory;\n+\n class MainApplication : Application(), ReactApplication {\n\n   override val reactNativeHost: ReactNativeHost =\n      object : DefaultReactNativeHost(this) {\n        override fun getPackages(): List\u003cReactPackage\u003e =\n            PackageList(this).packages.apply {\n              // Packages that cannot be auto linked yet can be added manually here, for example:\n              // add(MyReactNativePackage())\n            }\n        override fun getJSMainModuleName(): String = \"index\"\n\n        override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG\n\n        override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED\n        override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED\n+\n+       override fun getJavaScriptExecutorFactory(): JavaScriptExecutorFactory =\n+            V8ExecutorFactory(\n+                applicationContext,\n+                packageName,\n+                AndroidInfoHelpers.getFriendlyDeviceName(),\n+                useDeveloperSupport\n+            )\n       };\n\n    override val reactHost: ReactHost\n```\n\n4. Disable Hermes\n\n```diff\n--- a/android/gradle.properties\n+++ b/android/gradle.properties\n@@ -41,4 +41,4 @@ newArchEnabled=false\n\n # Use this property to enable or disable the Hermes JS engine.\n # If set to false, you will be using JSC instead.\n-hermesEnabled=true\n+hermesEnabled=false\n```\n\n5. `yarn android`\n\n6. You can verify whether it works by evaluating the `global._v8runtime().version` JavaScript statement.\n\n## Builtin JavaScript object\n\n`global._v8runtime()` has some builtin information such as v8 version.\n\n```js\nconsole.log(`V8 version is ${global._v8runtime().version}`);\n```\n\nPlease note that `global._v8runtime()` existed only for V8 enabled environment but not React Native remote debugging mode.\nFor remote debugging mode, the JavaScript actually runs on Chrome from your host and there is no V8Runtime.\n\n## V8 Variants\n\n`react-native-v8` depends on a V8 shared library built from [v8-android-buildscripts](https://github.com/Kudo/v8-android-buildscripts). `v8-android-jit` is the recommended V8 variant. This is a full featured V8 with both [JIT](https://en.wikipedia.org/wiki/Just-in-time_compilation) and [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl). We provide other V8 variants to fulfill your needs.\nFor instance, if you want to reduce memory usage, the non JIT variant, aka [V8 lite mode](https://v8.dev/blog/v8-lite).\nFor detailed V8 features, please check [the v8-android-buildscripts feature flags](https://github.com/Kudo/v8-android-buildscripts/blob/master/README.md#v8-feature-flags).\n\n| Package name            | JIT | Intl |\n| ----------------------- | --- | ---- |\n| `v8-android-jit`        | Yes | Yes  |\n| `v8-android-jit-nointl` | Yes | No   |\n| `v8-android`            | No  | Yes  |\n| `v8-android-nointl`     | No  | No   |\n\n## iOS Support (Experimental)\n\nYou could try the experimental ios support on an Expo project which SDK version is greater or equal to 48.\n\nFor managed projects, you can install through the single command:\n\n```sh\n$ npx expo install react-native-v8 v8-ios\n```\n\n- Please make sure you have [`\"ios.jsEngine\": \"jsc\"`](https://docs.expo.dev/versions/latest/config/app/#jsengine-1).\n\nFor bare projects, you can run `npx expo prebuild -p ios --clean` after the installation to prebuild again.\n\n## FAQ\n\n### How to reduce APK size ?\n\nThe V8 currently bundled by default supports [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) and the ICU data costs about 7MiB per ABI. If you are not going to use `Intl`, you could use no-Intl version to reduce APK size. (jsc-android have no Intl by default)\n\n## TODO\n\n- [x] Performance comparison with JavaScriptCore in React Native\n\n  Please check https://github.com/Kudo/react-native-js-benchmark for the benchmark and result\n\n- [x] V8 inspector integration\n- [ ] V8 snapshot integration\n- [ ] V8 code cache experiment\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKudo%2Freact-native-v8","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKudo%2Freact-native-v8","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKudo%2Freact-native-v8/lists"}