Skip to content

Commit 6f7cb08

Browse files
authored
Add Expo integration (#111)
* add expo adapter * add config plugin * update doc * update doc * update package name
1 parent c7e50dd commit 6f7cb08

File tree

15 files changed

+8445
-94
lines changed

15 files changed

+8445
-94
lines changed

.gitignore

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
package-lock.json
2-
/build
3-
/dist
4-
5-
scripts/depot_tools
6-
v8/
7-
!android/src/main/java/io/csie/kudo/reactnative/v8/
8-
91
# Created by https://www.gitignore.io/api/node,android,reactnative,intellij+all,androidstudio,visualstudiocode
102

113
### Android ###
@@ -448,3 +440,13 @@ gradle-app.setting
448440

449441

450442
# End of https://www.gitignore.io/api/node,android,reactnative,intellij+all,androidstudio,visualstudiocode
443+
444+
package-lock.json
445+
/build
446+
/dist
447+
448+
scripts/depot_tools
449+
v8/
450+
!android/src/main/java/io/csie/kudo/reactnative/v8/
451+
452+
!plugin/build/

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55

66
This 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.
77

8+
## Installation for Expo projects (>= SDK 45)
9+
10+
For managed projects, you can install through the single command:
11+
12+
```sh
13+
$ expo install react-native-v8 expo-build-properties
14+
```
15+
16+
- Please make sure you don't have [`"jsEngine": "hermes"`](https://docs.expo.dev/guides/using-hermes/#android-setup).
17+
18+
For bare projects, you can run `expo prebuild -p android --clean` after the installation to prebuild again.
19+
820
## Installation for React Native >= 0.66
921

1022
1. Install `react-native-v8` and a [v8-android variant](#v8-variants). For example, the `v8-android-jit`:
@@ -28,6 +40,7 @@ $ yarn add react-native-v8 v8-android-jit
2840
+ exclude "**/libjsc.so"
2941
+ }
3042
}
43+
```
3144

3245
3. Setup V8 in the `MainApplication.java`.
3346

@@ -120,8 +133,6 @@ For detailed V8 features, please check [the v8-android-buildscripts feature flag
120133
| `v8-android` | No | Yes |
121134
| `v8-android-nointl` | No | No |
122135

123-
124-
125136
## iOS Support (Experimented)
126137

127138
We did have experimented iOS support. To adopt V8 for Xcodeproj gets a little complicated, so we have a pre-shaped template.

app.plugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./plugin/build/withV8ExpoAdapter');

expo-module.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"platforms": ["android"],
3+
"android": {
4+
"gradlePath": "expo/build.gradle"
5+
}
6+
}

expo/build.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 650 Industries. All rights reserved.
3+
* Copyright (c) Kudo Chien.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
apply plugin: 'com.android.library'
9+
10+
buildscript {
11+
// Simple helper that allows the root project to override versions declared by this library.
12+
ext.safeExtGet = { prop, fallback ->
13+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
14+
}
15+
}
16+
17+
android {
18+
compileSdkVersion safeExtGet("compileSdkVersion", 31)
19+
20+
compileOptions {
21+
sourceCompatibility JavaVersion.VERSION_11
22+
targetCompatibility JavaVersion.VERSION_11
23+
}
24+
25+
defaultConfig {
26+
minSdkVersion safeExtGet("minSdkVersion", 21)
27+
targetSdkVersion safeExtGet("targetSdkVersion", 31)
28+
versionCode 1
29+
versionName '1.0.0'
30+
}
31+
lintOptions {
32+
abortOnError false
33+
}
34+
}
35+
36+
dependencies {
37+
implementation 'com.facebook.react:react-native:+'
38+
implementation project(':expo-modules-core')
39+
implementation project(':react-native-v8')
40+
}

expo/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest package="io.csie.kudo.reactnative.v8.expo" xmlns:android="http://schemas.android.com/apk/res/android">
2+
3+
</manifest>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) Kudo Chien.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
package io.csie.kudo.reactnative.v8.expo;
8+
9+
import android.content.Context;
10+
11+
import androidx.annotation.Nullable;
12+
13+
import com.facebook.react.bridge.JavaScriptExecutorFactory;
14+
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers;
15+
16+
import java.util.Collections;
17+
import java.util.List;
18+
19+
import expo.modules.core.interfaces.Package;
20+
import expo.modules.core.interfaces.ReactNativeHostHandler;
21+
import io.csie.kudo.reactnative.v8.executor.V8ExecutorFactory;
22+
23+
public class V8ExpoAdapterPackage implements Package {
24+
@Override
25+
public List<? extends ReactNativeHostHandler> createReactNativeHostHandlers(Context context) {
26+
return Collections.singletonList(new ReactNativeHostHandler() {
27+
28+
@Nullable
29+
@Override
30+
public String getBundleAssetName(boolean useDeveloperSupport) {
31+
final String v8BundleAssetName = V8ExecutorFactory.getBundleAssetName(context, useDeveloperSupport);
32+
if (v8BundleAssetName != null) {
33+
return v8BundleAssetName;
34+
}
35+
return null;
36+
}
37+
38+
@Override
39+
public JavaScriptExecutorFactory getJavaScriptExecutorFactory() {
40+
return new V8ExecutorFactory(
41+
context,
42+
context.getPackageName(),
43+
AndroidInfoHelpers.getFriendlyDeviceName(),
44+
BuildConfig.DEBUG);
45+
}
46+
});
47+
}
48+
}

index.js

Whitespace-only changes.

package.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
"name": "react-native-v8",
33
"version": "1.2.0",
44
"description": "Opt-in V8 runtime for React Native Android",
5+
"scripts": {
6+
"build": "expo-module build",
7+
"clean": "expo-module clean",
8+
"expo-module": "expo-module",
9+
"build:plugin": "expo-module build plugin",
10+
"clean:plugin": "expo-module clean plugin"
11+
},
512
"repository": {
613
"type": "git",
714
"url": "git+https://github.com/Kudo/react-native-v8.git"
@@ -20,9 +27,26 @@
2027
"android/",
2128
"!android/build",
2229
"!android/.cxx",
30+
"!android/.gradle",
31+
"index.js",
32+
"expo/",
33+
"!expo/build",
34+
"expo-module.config.json",
35+
"app.plugin.js",
36+
"plugin/",
2337
"src/"
2438
],
2539
"devDependencies": {
26-
"clang-format": "^1.8.0"
40+
"clang-format": "^1.8.0",
41+
"expo-build-properties": "^0.1.0",
42+
"expo-module-scripts": "^2.0.0"
43+
},
44+
"peerDependencies": {
45+
"expo-build-properties": "^0.1.0"
46+
},
47+
"peerDependenciesMeta": {
48+
"expo-build-properties": {
49+
"optional": true
50+
}
2751
}
2852
}

plugin/build/withV8ExpoAdapter.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { ConfigPlugin } from "@expo/config-plugins";
2+
declare const _default: ConfigPlugin<void>;
3+
export default _default;

0 commit comments

Comments
 (0)