diff --git a/.circleci/config.yml b/.circleci/config.yml index 1dcda8bfb..7f290b588 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/README.md b/README.md index 7356a82a9..5312ebb7c 100644 --- a/README.md +++ b/README.md @@ -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 { @@ -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! @@ -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 { diff --git a/lib/cppruntime/build.gradle b/lib/cppruntime/build.gradle new file mode 100644 index 000000000..af4350ebf --- /dev/null +++ b/lib/cppruntime/build.gradle @@ -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" + } + } +} diff --git a/lib/cppruntime/src/main/AndroidManifest.xml b/lib/cppruntime/src/main/AndroidManifest.xml new file mode 100644 index 000000000..b79b31ca7 --- /dev/null +++ b/lib/cppruntime/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/lib/settings.gradle b/lib/settings.gradle index 46d63710c..baa5c84a9 100644 --- a/lib/settings.gradle +++ b/lib/settings.gradle @@ -1,3 +1,4 @@ rootProject.name = 'JavaScriptCore Lib' include ':android-jsc' +include ':cppruntime' diff --git a/scripts/compile/common.sh b/scripts/compile/common.sh index 1219baea3..104366d8c 100755 --- a/scripts/compile/common.sh +++ b/scripts/compile/common.sh @@ -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 diff --git a/scripts/compile/jsc.sh b/scripts/compile/jsc.sh index 44176d9b2..cbf29ee4c 100755 --- a/scripts/compile/jsc.sh +++ b/scripts/compile/jsc.sh @@ -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 diff --git a/scripts/compile/toolchain.sh b/scripts/compile/toolchain.sh index 8a2f4465d..d240b69f8 100755 --- a/scripts/compile/toolchain.sh +++ b/scripts/compile/toolchain.sh @@ -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 diff --git a/scripts/start.sh b/scripts/start.sh index 99e10ec02..bfb291f53 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -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" \ @@ -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") @@ -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() { @@ -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