Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Expo integration #111

Merged
merged 5 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
package-lock.json
/build
/dist

scripts/depot_tools
v8/
!android/src/main/java/io/csie/kudo/reactnative/v8/

# Created by https://www.gitignore.io/api/node,android,reactnative,intellij+all,androidstudio,visualstudiocode

### Android ###
Expand Down Expand Up @@ -448,3 +440,13 @@ gradle-app.setting


# End of https://www.gitignore.io/api/node,android,reactnative,intellij+all,androidstudio,visualstudiocode

package-lock.json
/build
/dist

scripts/depot_tools
v8/
!android/src/main/java/io/csie/kudo/reactnative/v8/

!plugin/build/
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@

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.

## Installation for Expo projects (>= SDK 45)

For managed projects, you can install through the single command:

```sh
$ expo install react-native-v8 expo-build-properties
```

- Please make sure you don't have [`"jsEngine": "hermes"`](https://docs.expo.dev/guides/using-hermes/#android-setup).

For bare projects, you can run `expo prebuild -p android --clean` after the installation to prebuild again.

## Installation for React Native >= 0.66

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

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

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



## iOS Support (Experimented)

We did have experimented iOS support. To adopt V8 for Xcodeproj gets a little complicated, so we have a pre-shaped template.
Expand Down
1 change: 1 addition & 0 deletions app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./plugin/build/withV8ExpoAdapter');
6 changes: 6 additions & 0 deletions expo-module.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"platforms": ["android"],
"android": {
"gradlePath": "expo/build.gradle"
}
}
40 changes: 40 additions & 0 deletions expo/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 650 Industries. All rights reserved.
* Copyright (c) Kudo Chien.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
apply plugin: 'com.android.library'

buildscript {
// Simple helper that allows the root project to override versions declared by this library.
ext.safeExtGet = { prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
}

android {
compileSdkVersion safeExtGet("compileSdkVersion", 31)

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 21)
targetSdkVersion safeExtGet("targetSdkVersion", 31)
versionCode 1
versionName '1.0.0'
}
lintOptions {
abortOnError false
}
}

dependencies {
implementation 'com.facebook.react:react-native:+'
implementation project(':expo-modules-core')
implementation project(':react-native-v8')
}
3 changes: 3 additions & 0 deletions expo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest package="io.csie.kudo.reactnative.v8.expo" xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) Kudo Chien.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package io.csie.kudo.reactnative.v8.expo;

import android.content.Context;

import androidx.annotation.Nullable;

import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers;

import java.util.Collections;
import java.util.List;

import expo.modules.core.interfaces.Package;
import expo.modules.core.interfaces.ReactNativeHostHandler;
import io.csie.kudo.reactnative.v8.executor.V8ExecutorFactory;

public class V8ExpoAdapterPackage implements Package {
@Override
public List<? extends ReactNativeHostHandler> createReactNativeHostHandlers(Context context) {
return Collections.singletonList(new ReactNativeHostHandler() {

@Nullable
@Override
public String getBundleAssetName(boolean useDeveloperSupport) {
final String v8BundleAssetName = V8ExecutorFactory.getBundleAssetName(context, useDeveloperSupport);
if (v8BundleAssetName != null) {
return v8BundleAssetName;
}
return null;
}

@Override
public JavaScriptExecutorFactory getJavaScriptExecutorFactory() {
return new V8ExecutorFactory(
context,
context.getPackageName(),
AndroidInfoHelpers.getFriendlyDeviceName(),
BuildConfig.DEBUG);
}
});
}
}
Empty file added index.js
Empty file.
26 changes: 25 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"name": "react-native-v8",
"version": "1.2.0",
"description": "Opt-in V8 runtime for React Native Android",
"scripts": {
"build": "expo-module build",
"clean": "expo-module clean",
"expo-module": "expo-module",
"build:plugin": "expo-module build plugin",
"clean:plugin": "expo-module clean plugin"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Kudo/react-native-v8.git"
Expand All @@ -20,9 +27,26 @@
"android/",
"!android/build",
"!android/.cxx",
"!android/.gradle",
"index.js",
"expo/",
"!expo/build",
"expo-module.config.json",
"app.plugin.js",
"plugin/",
"src/"
],
"devDependencies": {
"clang-format": "^1.8.0"
"clang-format": "^1.8.0",
"expo-build-properties": "^0.1.0",
"expo-module-scripts": "^2.0.0"
},
"peerDependencies": {
"expo-build-properties": "^0.1.0"
},
"peerDependenciesMeta": {
"expo-build-properties": {
"optional": true
}
}
}
3 changes: 3 additions & 0 deletions plugin/build/withV8ExpoAdapter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { ConfigPlugin } from "@expo/config-plugins";
declare const _default: ConfigPlugin<void>;
export default _default;
15 changes: 15 additions & 0 deletions plugin/build/withV8ExpoAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const config_plugins_1 = require("@expo/config-plugins");
const expo_build_properties_1 = require("expo-build-properties");
const withV8ExpoAdapter = (config) => {
return (0, expo_build_properties_1.withBuildProperties)(config, {
android: {
packagingOptions: {
exclude: ["**/**/libjsc*"],
},
},
});
};
const pkg = require("react-native-v8/package.json");
exports.default = (0, config_plugins_1.createRunOncePlugin)(withV8ExpoAdapter, pkg.name, pkg.version);
17 changes: 17 additions & 0 deletions plugin/src/withV8ExpoAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createRunOncePlugin } from "@expo/config-plugins";
import type { ConfigPlugin } from "@expo/config-plugins";
import { withBuildProperties } from "expo-build-properties";

const withV8ExpoAdapter: ConfigPlugin = (config) => {
return withBuildProperties(config, {
android: {
packagingOptions: {
exclude: ["**/**/libjsc*"],
},
},
});
};

const pkg = require("react-native-v8/package.json");

export default createRunOncePlugin(withV8ExpoAdapter, pkg.name, pkg.version);
9 changes: 9 additions & 0 deletions plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "expo-module-scripts/tsconfig.plugin",
"compilerOptions": {
"outDir": "build",
"rootDir": "src"
},
"include": ["./src"],
"exclude": ["**/__mocks__/*", "**/__tests__/*"]
}
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @generated by expo-module-scripts
{
"extends": "expo-module-scripts/tsconfig.base",
"compilerOptions": {
"outDir": "./build"
},
"include": ["./src"],
"exclude": ["**/__mocks__/*", "**/__tests__/*"]
}
Loading