Skip to content

Commit d4f4f90

Browse files
Kudokmagiera
authored andcommitted
Update for RN 0.60 (#95)
Newer RN manages JSC by node dependency. facebook/react-native#24276 Integrate and update JSC would be easier than before. However, [in the PR comments](facebook/react-native#24276) there are still some enhancements could be done. 1. Align NDK version to prevent potential ABI incompatible issue. 2. Remove libc++_shared.so from jsc-android.aar, so that user don't need to use `packagingOptions.pickFirst` to exclude them. For RN 0.58 and before, since it was built by gcc. These is no libc++_shared.so but libgnustl_shared.so. For jsc-android side, provide an android-jsc-cppruntime.aar for user to add libc++_shared.so.
1 parent b1fd6c3 commit d4f4f90

File tree

9 files changed

+169
-8
lines changed

9 files changed

+169
-8
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
working_directory: ~/jsc-android-buildscripts
66
machine: true
77
environment:
8-
NDK_VERSION: r18
8+
NDK_VERSION: r17c
99
SDK_VERSION: sdk-tools-linux-3859397.zip
1010
ANDROID_HOME: /home/circleci/android-sdk
1111
ANDROID_NDK: /home/circleci/android-ndk

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,78 @@ On load, JSC prints the version out to logcat, under "JavaScriptCore.Version" ta
4545

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

48+
### For React Native version 0.60 and newer
49+
50+
1. Update `jsc-android`:
51+
52+
```
53+
yarn add jsc-android
54+
55+
# Or if you would like to try latest version
56+
# yarn add 'jsc-android@canary`
57+
58+
```
59+
60+
2. You're done, rebuild your app and enjoy updated version of JSC on android!
61+
62+
### For React Native version 0.59
63+
64+
1. Add `jsc-android` to the "dependencies" section in your `package.json`:
65+
```diff
66+
dependencies {
67+
+ "jsc-android": "241213.x.x",
68+
```
69+
70+
then run `npm install` or `yarn` (depending which npm client you use) in order for the new dependency to be installed in `node_modules`
71+
72+
2. Modify `android/build.gradle` file to add new local maven repository packaged in the `jsc-android` package to the search path:
73+
```diff
74+
allprojects {
75+
repositories {
76+
mavenLocal()
77+
jcenter()
78+
maven {
79+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
80+
url "$rootDir/../node_modules/react-native/android"
81+
}
82+
+ maven {
83+
+ // Local Maven repo containing AARs with JSC library built for Android
84+
+ url "$rootDir/../node_modules/jsc-android/dist"
85+
+ }
86+
}
87+
}
88+
```
89+
90+
3. Update your app's `build.gradle` file located in `android/app/build.gradle` to add the JSC dependencey. Please make sure the dependency should put before React Native dependency.
91+
92+
```diff
93+
94+
dependencies {
95+
+ // Make sure to put android-jsc at the the first
96+
+ implementation "org.webkit:android-jsc:r241213"
97+
+
98+
compile fileTree(dir: "libs", include: ["*.jar"])
99+
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
100+
implementation "com.facebook.react:react-native:+" // From node_modules
101+
}
102+
```
103+
104+
4. Update your app's `build.gradle` file located in `android/app/build.gradle` to use first matched JSC library.
105+
106+
```diff
107+
android {
108+
// ...
109+
+ packagingOptions {
110+
+ pickFirst '**/libjsc.so'
111+
+ pickFirst '**/libc++_shared.so'
112+
+ }
113+
}
114+
```
115+
116+
5. You're done, rebuild your app and enjoy updated version of JSC on android!
117+
118+
### For React Native version 0.58 below
119+
48120
1. Add `jsc-android` to the "dependencies" section in your `package.json`:
49121
```diff
50122
dependencies {
@@ -84,6 +156,10 @@ allprojects {
84156

85157
dependencies {
86158
compile fileTree(dir: "libs", include: ["*.jar"])
159+
+ // ...
160+
+ implementation 'org.webkit:android-jsc-cppruntime:+'
161+
+ // For even older gradle
162+
+ // compile 'org.webkit:android-jsc-cppruntime:+'
87163
```
88164

89165
4. You're done, rebuild your app and enjoy updated version of JSC on android!
@@ -93,6 +169,35 @@ International variant includes ICU i18n library and necessary data allowing to u
93169

94170
To use this variant instead replace the third installation step with:
95171

172+
For React Native version 0.60 and newer, your build.gradle should have a flag to enable this feature.
173+
174+
```diff
175+
/**
176+
* Use the international variant of JavaScriptCore
177+
* This variant includes the ICU i18n library to make APIs like `Date.toLocaleString`
178+
* and `String.localeCompare` work when using with locales other than en-US.
179+
* Note that this variant is about 6MiB larger per architecture than the default.
180+
*/
181+
- def useIntlJsc = false
182+
+ def useIntlJsc = true
183+
```
184+
185+
For React Native version 0.59, replace original artifact id with `android-jsc-intl`
186+
187+
```diff
188+
189+
dependencies {
190+
+ // Make sure to put android-jsc at the the first
191+
+ implementation "org.webkit:android-jsc-intl:r241213"
192+
+
193+
compile fileTree(dir: "libs", include: ["*.jar"])
194+
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
195+
implementation "com.facebook.react:react-native:+" // From node_modules
196+
}
197+
```
198+
199+
For React Native version 0.58 below, replace original `resolutionStrategy` with this.
200+
96201
```diff
97202
+configurations.all {
98203
+ resolutionStrategy {

lib/cppruntime/build.gradle

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 28
5+
6+
defaultConfig {
7+
minSdkVersion 16
8+
targetSdkVersion 28
9+
versionCode 1
10+
versionName "1.0"
11+
}
12+
13+
sourceSets {
14+
main {
15+
jniLibs.srcDirs = ["${rootDir}/../build/cppruntime"]
16+
}
17+
}
18+
}
19+
20+
dependencies {}
21+
22+
apply plugin: 'maven'
23+
24+
task createAAR(type: Upload) {
25+
def distDir = "${rootDir}/../dist"
26+
27+
def revision = project.findProperty("revision") ?: "".replaceAll("\\s", "")
28+
29+
doFirst {
30+
if (!revision) throw new RuntimeException("expecting --project-prop revision=??? but was empty")
31+
}
32+
33+
project.group = "org.webkit"
34+
project.version = "r${revision}"
35+
36+
configuration = configurations.archives
37+
repositories.mavenDeployer {
38+
repository url: "file://${distDir}"
39+
pom.project {
40+
name "android-jsc"
41+
artifactId "android-jsc-cppruntime"
42+
packaging "aar"
43+
}
44+
}
45+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="org.webkit.androidjsc" />

lib/settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
rootProject.name = 'JavaScriptCore Lib'
22

33
include ':android-jsc'
4+
include ':cppruntime'

scripts/compile/common.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,6 @@ JSC_CFLAGS="$COMMON_CFLAGS -DU_STATIC_IMPLEMENTATION=1 -DU_SHOW_CPLUSPLUS_API=0"
160160

161161
INSTALL_DIR=$ROOTDIR/build/compiled/$JNI_ARCH
162162
mkdir -p $INSTALL_DIR
163+
164+
INSTALL_CPPRUNTIME_DIR=$ROOTDIR/build/cppruntime/$JNI_ARCH
165+
mkdir -p $INSTALL_CPPRUNTIME_DIR

scripts/compile/jsc.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,3 @@ $TARGETDIR/webkit/Tools/Scripts/build-webkit \
7171

7272
cp $TARGETDIR/webkit/WebKitBuild/Release/lib/libjsc.so $INSTALL_DIR
7373
mv $TARGETDIR/webkit/WebKitBuild $TARGETDIR/webkit/${CROSS_COMPILE_PLATFORM}-${FLAVOR}
74-
cp $TOOLCHAIN_LINK_DIR/libc++_shared.so $INSTALL_DIR

scripts/compile/toolchain.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ $ANDROID_NDK/build/tools/make_standalone_toolchain.py \
1010
--install-dir $TOOLCHAIN_DIR \
1111
--arch $ARCH \
1212
--stl libc++
13+
14+
cp $TOOLCHAIN_LINK_DIR/libc++_shared.so $INSTALL_CPPRUNTIME_DIR

scripts/start.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ patchAndMakeICU() {
2020
rm -rf $TARGETDIR/icu/host
2121
mkdir -p $TARGETDIR/icu/host
2222
cd $TARGETDIR/icu/host
23-
23+
2424
$TARGETDIR/icu/source/runConfigureICU Linux \
2525
--prefix=$PWD/prebuilts \
2626
CFLAGS="-Os" \
@@ -53,7 +53,7 @@ prep() {
5353
printf "\n\n\t\t===================== copy downloaded sources =====================\n\n"
5454
rm -rf $TARGETDIR
5555
cp -Rf $ROOTDIR/build/download $TARGETDIR
56-
56+
5757
patchAndMakeICU
5858
patchJsc
5959
# origs=$(find $ROOTDIR/build/target -name "*.orig")
@@ -67,10 +67,12 @@ compile() {
6767
}
6868

6969
createAAR() {
70-
printf "\n\n\t\t===================== create aar =====================\n\n"
70+
TARGET=$1
71+
printf "\n\n\t\t===================== create aar :$TARGET: =====================\n\n"
7172
cd $ROOTDIR/lib
72-
./gradlew clean createAAR --project-prop revision="$REVISION" --project-prop i18n="${I18N}"
73+
./gradlew clean :$TARGET:createAAR --project-prop revision="$REVISION" --project-prop i18n="${I18N}"
7374
cd $ROOTDIR
75+
unset TARGET
7476
}
7577

7678
copyHeaders() {
@@ -82,12 +84,14 @@ copyHeaders() {
8284
export I18N=false
8385
prep
8486
compile
85-
createAAR
87+
createAAR "android-jsc"
8688

8789
export I18N=true
8890
prep
8991
compile
90-
createAAR
92+
createAAR "android-jsc"
93+
94+
createAAR "cppruntime"
9195

9296
copyHeaders
9397

0 commit comments

Comments
 (0)