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

Update for RN 0.60 #95

Merged
merged 4 commits into from
Apr 25, 2019
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
working_directory: ~/jsc-android-buildscripts
machine: true
environment:
NDK_VERSION: r18
NDK_VERSION: r17c
SDK_VERSION: sdk-tools-linux-3859397.zip
ANDROID_HOME: /home/circleci/android-sdk
ANDROID_NDK: /home/circleci/android-ndk
Expand Down
105 changes: 105 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,78 @@ On load, JSC prints the version out to logcat, under "JavaScriptCore.Version" ta

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

### For React Native version 0.60 and newer

1. Update `jsc-android`:

```
yarn add jsc-android

# Or if you would like to try latest version
# yarn add 'jsc-android@canary`

```

2. You're done, rebuild your app and enjoy updated version of JSC on android!

### For React Native version 0.59

1. Add `jsc-android` to the "dependencies" section in your `package.json`:
```diff
dependencies {
+ "jsc-android": "241213.x.x",
```

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

2. Modify `android/build.gradle` file to add new local maven repository packaged in the `jsc-android` package to the search path:
```diff
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/dist"
+ }
}
}
```

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.

```diff

dependencies {
+ // Make sure to put android-jsc at the the first
+ implementation "org.webkit:android-jsc:r241213"
+
compile fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
}
```

4. Update your app's `build.gradle` file located in `android/app/build.gradle` to use first matched JSC library.

```diff
android {
// ...
+ packagingOptions {
+ pickFirst '**/libjsc.so'
+ pickFirst '**/libc++_shared.so'
+ }
}
```

5. You're done, rebuild your app and enjoy updated version of JSC on android!

### For React Native version 0.58 below

1. Add `jsc-android` to the "dependencies" section in your `package.json`:
```diff
dependencies {
Expand Down Expand Up @@ -84,6 +156,10 @@ allprojects {

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

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

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

For React Native version 0.60 and newer, your build.gradle should have a flag to enable this feature.

```diff
/**
* Use the international variant of JavaScriptCore
* This variant includes the ICU i18n library to make APIs like `Date.toLocaleString`
* and `String.localeCompare` work when using with locales other than en-US.
* Note that this variant is about 6MiB larger per architecture than the default.
*/
- def useIntlJsc = false
+ def useIntlJsc = true
```

For React Native version 0.59, replace original artifact id with `android-jsc-intl`

```diff

dependencies {
+ // Make sure to put android-jsc at the the first
+ implementation "org.webkit:android-jsc-intl:r241213"
+
compile fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
}
```

For React Native version 0.58 below, replace original `resolutionStrategy` with this.

```diff
+configurations.all {
+ resolutionStrategy {
Expand Down
45 changes: 45 additions & 0 deletions lib/cppruntime/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
}

sourceSets {
main {
jniLibs.srcDirs = ["${rootDir}/../build/cppruntime"]
}
}
}

dependencies {}

apply plugin: 'maven'

task createAAR(type: Upload) {
def distDir = "${rootDir}/../dist"

def revision = project.findProperty("revision") ?: "".replaceAll("\\s", "")

doFirst {
if (!revision) throw new RuntimeException("expecting --project-prop revision=??? but was empty")
}

project.group = "org.webkit"
project.version = "r${revision}"

configuration = configurations.archives
repositories.mavenDeployer {
repository url: "file://${distDir}"
pom.project {
name "android-jsc"
artifactId "android-jsc-cppruntime"
packaging "aar"
}
}
}
2 changes: 2 additions & 0 deletions lib/cppruntime/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.webkit.androidjsc" />
1 change: 1 addition & 0 deletions lib/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rootProject.name = 'JavaScriptCore Lib'

include ':android-jsc'
include ':cppruntime'
3 changes: 3 additions & 0 deletions scripts/compile/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,6 @@ JSC_CFLAGS="$COMMON_CFLAGS -DU_STATIC_IMPLEMENTATION=1 -DU_SHOW_CPLUSPLUS_API=0"

INSTALL_DIR=$ROOTDIR/build/compiled/$JNI_ARCH
mkdir -p $INSTALL_DIR

INSTALL_CPPRUNTIME_DIR=$ROOTDIR/build/cppruntime/$JNI_ARCH
mkdir -p $INSTALL_CPPRUNTIME_DIR
1 change: 0 additions & 1 deletion scripts/compile/jsc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,3 @@ $TARGETDIR/webkit/Tools/Scripts/build-webkit \

cp $TARGETDIR/webkit/WebKitBuild/Release/lib/libjsc.so $INSTALL_DIR
mv $TARGETDIR/webkit/WebKitBuild $TARGETDIR/webkit/${CROSS_COMPILE_PLATFORM}-${FLAVOR}
cp $TOOLCHAIN_LINK_DIR/libc++_shared.so $INSTALL_DIR
2 changes: 2 additions & 0 deletions scripts/compile/toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ $ANDROID_NDK/build/tools/make_standalone_toolchain.py \
--install-dir $TOOLCHAIN_DIR \
--arch $ARCH \
--stl libc++

cp $TOOLCHAIN_LINK_DIR/libc++_shared.so $INSTALL_CPPRUNTIME_DIR
16 changes: 10 additions & 6 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ patchAndMakeICU() {
rm -rf $TARGETDIR/icu/host
mkdir -p $TARGETDIR/icu/host
cd $TARGETDIR/icu/host

$TARGETDIR/icu/source/runConfigureICU Linux \
--prefix=$PWD/prebuilts \
CFLAGS="-Os" \
Expand Down Expand Up @@ -53,7 +53,7 @@ prep() {
printf "\n\n\t\t===================== copy downloaded sources =====================\n\n"
rm -rf $TARGETDIR
cp -Rf $ROOTDIR/build/download $TARGETDIR

patchAndMakeICU
patchJsc
# origs=$(find $ROOTDIR/build/target -name "*.orig")
Expand All @@ -67,10 +67,12 @@ compile() {
}

createAAR() {
printf "\n\n\t\t===================== create aar =====================\n\n"
TARGET=$1
printf "\n\n\t\t===================== create aar :$TARGET: =====================\n\n"
cd $ROOTDIR/lib
./gradlew clean createAAR --project-prop revision="$REVISION" --project-prop i18n="${I18N}"
./gradlew clean :$TARGET:createAAR --project-prop revision="$REVISION" --project-prop i18n="${I18N}"
cd $ROOTDIR
unset TARGET
}

copyHeaders() {
Expand All @@ -82,12 +84,14 @@ copyHeaders() {
export I18N=false
prep
compile
createAAR
createAAR "android-jsc"

export I18N=true
prep
compile
createAAR
createAAR "android-jsc"

createAAR "cppruntime"

copyHeaders

Expand Down