From 0f20473c72eb34bfe34509e53f75b550818b046d Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Thu, 4 Apr 2019 14:12:44 -0700 Subject: [PATCH] Use node package dependency to manage JSC version (#24276) Summary: In origin approach, we packed libjsc.so inside react-native.aar and it is difficult for user to choose different JSC variants. E.g., [the Intl supported version](https://github.com/react-native-community/jsc-android-buildscripts#international-variant). This change list allows application to determine JSC versions or variants by npm/yarn package. There is a |useIntlJsc| flag in build.gradle, it will use the same JSC version but with Intl support. `yarn add jsc-android@canary` [Android] [Changed] - Allow application to select different JSC variants **MIGRATION** Note that there are some changes in build.gradle. Existing application needs to change their android/build.gradle and android/app/build.gradle. Hopefully, the rn-diff-purge should handle the case well. Pull Request resolved: https://github.com/facebook/react-native/pull/24276 Differential Revision: D14752359 Pulled By: cpojer fbshipit-source-id: a4bfb135ad8e328f404a2d1a062412f40ebf4622 --- RNTester/android/app/build.gradle | 20 ++++++++++++++++++++ ReactAndroid/build.gradle | 18 +++++------------- ReactAndroid/gradle.properties | 1 - build.gradle | 4 ++++ package.json | 1 + scripts/circleci/gradle_download_deps.sh | 2 +- template/android/app/build.gradle | 23 +++++++++++++++++++++++ template/android/build.gradle | 11 ++++++++--- yarn.lock | 5 +++++ 9 files changed, 67 insertions(+), 18 deletions(-) diff --git a/RNTester/android/app/build.gradle b/RNTester/android/app/build.gradle index 4a6a9aad2c5057..3ef02339fa931a 100644 --- a/RNTester/android/app/build.gradle +++ b/RNTester/android/app/build.gradle @@ -91,6 +91,14 @@ def enableSeparateBuildPerCPUArchitecture = true */ def enableProguardInReleaseBuilds = true +/** + * 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 + android { compileSdkVersion 28 @@ -132,6 +140,12 @@ android { signingConfig signingConfigs.release } } + packagingOptions { + pickFirst '**/armeabi-v7a/libc++_shared.so' + pickFirst '**/x86/libc++_shared.so' + pickFirst '**/x86_64/libc++_shared.so' + pickFirst '**/arm64-v8a/libc++_shared.so' + } } dependencies { @@ -139,4 +153,10 @@ dependencies { // Build React Native from source implementation project(':ReactAndroid') + + if (useIntlJsc) { + implementation 'org.webkit:android-jsc-intl:+' + } else { + implementation 'org.webkit:android-jsc:+' + } } diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 060af22adbaaea..d79a9b9bafd626 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -133,21 +133,14 @@ task prepareGlog(dependsOn: dependenciesPath ? [] : [downloadGlog], type: Copy) } } -task downloadJSC(dependsOn: createNativeDepsDirectories, type: Download) { - src("https://registry.npmjs.org/jsc-android/-/jsc-android-${JSC_VERSION}.tgz") - onlyIfNewer(true) - overwrite(false) - dest(new File(downloadsDir, "jsc-${JSC_VERSION}.tar.gz")) -} - // Create Android.mk library module based on jsc from npm -task prepareJSC(dependsOn: downloadJSC) { +task prepareJSC { doLast { - def jscTar = tarTree(downloadJSC.dest) - def jscAAR = jscTar.matching({ it.include "**/android-jsc/**/*.aar" }).singleFile + def jscPackageRoot = fileTree("$projectDir/../node_modules/jsc-android/dist") + def jscAAR = jscPackageRoot.matching({ it.include "**/android-jsc/**/*.aar" }).singleFile def soFiles = zipTree(jscAAR).matching({ it.include "**/*.so" }) - def headerFiles = jscTar.matching({ it.include "**/include/*.h" }) + def headerFiles = jscPackageRoot.matching({ it.include "**/include/*.h" }) copy { from(soFiles) @@ -168,7 +161,6 @@ task downloadNdkBuildDependencies { dependsOn(downloadDoubleConversion) dependsOn(downloadFolly) dependsOn(downloadGlog) - dependsOn(downloadJSC) } def getNdkBuildName() { @@ -255,8 +247,8 @@ task cleanReactNdkLib(type: Exec) { task packageReactNdkLibs(dependsOn: buildReactNdkLib, type: Copy) { from("$buildDir/react-ndk/all") - from("$thirdPartyNdkDir/jsc/jni") into("$buildDir/react-ndk/exported") + exclude("**/libjsc.so") } task packageReactNdkLibsForBuck(dependsOn: packageReactNdkLibs, type: Copy) { diff --git a/ReactAndroid/gradle.properties b/ReactAndroid/gradle.properties index 96305afe414853..00b3dcb0d10ff8 100644 --- a/ReactAndroid/gradle.properties +++ b/ReactAndroid/gradle.properties @@ -20,7 +20,6 @@ BOOST_VERSION=1_63_0 DOUBLE_CONVERSION_VERSION=1.1.6 FOLLY_VERSION=2018.10.22.00 GLOG_VERSION=0.3.5 -JSC_VERSION=236355.1.1 android.useAndroidX=true android.enableJetifier=true diff --git a/build.gradle b/build.gradle index e645fb920aebdd..9198857c2b19ae 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,10 @@ buildscript { allprojects { repositories { mavenLocal() + maven { + url("$rootDir/node_modules/jsc-android/dist") + } + google() jcenter() diff --git a/package.json b/package.json index b4cd40f9ecabe0..9aac5ed4e433d6 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "fbjs": "^1.0.0", "fbjs-scripts": "^1.1.0", "invariant": "^2.2.4", + "jsc-android": "^236355.1.1", "metro-babel-register": "0.52.0", "metro-react-native-babel-transformer": "0.52.0", "nullthrows": "^1.1.0", diff --git a/scripts/circleci/gradle_download_deps.sh b/scripts/circleci/gradle_download_deps.sh index d1877c89d5956a..dd3d781dc926e9 100755 --- a/scripts/circleci/gradle_download_deps.sh +++ b/scripts/circleci/gradle_download_deps.sh @@ -6,4 +6,4 @@ set -e -./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog :ReactAndroid:downloadJSC +./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog diff --git a/template/android/app/build.gradle b/template/android/app/build.gradle index d4064d1cd134c7..51342de4d06cba 100644 --- a/template/android/app/build.gradle +++ b/template/android/app/build.gradle @@ -96,6 +96,15 @@ def enableSeparateBuildPerCPUArchitecture = false */ def enableProguardInReleaseBuilds = false +/** + * Use international variant JavaScriptCore + * International variant includes ICU i18n library and necessary data allowing to use + * e.g. Date.toLocaleString and String.localeCompare that give correct results + * when using with locales other than en-US. + * Note that this variant is about 6MiB larger per architecture than default. + */ +def useIntlJsc = false + android { compileSdkVersion rootProject.ext.compileSdkVersion @@ -152,11 +161,25 @@ android { } } } + + packagingOptions { + pickFirst '**/armeabi-v7a/libc++_shared.so' + pickFirst '**/x86/libc++_shared.so' + pickFirst '**/arm64-v8a/libc++_shared.so' + pickFirst '**/x86_64/libc++_shared.so' + } } dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.facebook.react:react-native:+" // From node_modules + + // JSC from node_modules + if (useIntlJsc) { + implementation 'org.webkit:android-jsc-intl:+' + } else { + implementation 'org.webkit:android-jsc:+' + } } // Run this once to be able to run the application with BUCK diff --git a/template/android/build.gradle b/template/android/build.gradle index e7078ff33e250d..6b738db44078c0 100644 --- a/template/android/build.gradle +++ b/template/android/build.gradle @@ -23,11 +23,16 @@ buildscript { allprojects { repositories { mavenLocal() - google() - jcenter() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm - url "$rootDir/../node_modules/react-native/android" + url("$rootDir/../node_modules/react-native/android") + } + maven { + // Android JSC is installed from npm + url("$rootDir/../node_modules/jsc-android/dist") } + + google() + jcenter() } } diff --git a/yarn.lock b/yarn.lock index 0939cd7de07463..ff69e62286864c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4192,6 +4192,11 @@ jsbn@~0.1.0: resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" integrity sha1-peZUwuWi3rXyAdls77yoDA7y9RM= +jsc-android@^236355.1.1: + version "236355.1.1" + resolved "https://registry.yarnpkg.com/jsc-android/-/jsc-android-236355.1.1.tgz#43e153b722e3c60dd0595be4e7430baf65e67c9c" + integrity sha512-2py4f0McZIl/oH6AzPj1Ebutc58fyeLvwq6gyVYp1RsWr4qeLNHAPfW3kmfeVMz44oUBJMQ0lECZg9n4KBhHbQ== + jscodeshift@^0.6.2: version "0.6.2" resolved "https://registry.yarnpkg.com/jscodeshift/-/jscodeshift-0.6.2.tgz#bb648e6bce717a597d165781158b0d73b7fa99c3"