From 65a5d216235e522d03a1802fcb7e0589db8f3e29 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Wed, 3 Apr 2019 10:33:55 +0800 Subject: [PATCH 1/2] Use node package dependency to manage JSC version --- RNTester/android/app/build.gradle | 21 +++++++++++++++++++++ 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, 68 insertions(+), 18 deletions(-) diff --git a/RNTester/android/app/build.gradle b/RNTester/android/app/build.gradle index 4a6a9aad2c5057..8166b96ce44db5 100644 --- a/RNTester/android/app/build.gradle +++ b/RNTester/android/app/build.gradle @@ -91,6 +91,15 @@ def enableSeparateBuildPerCPUArchitecture = true */ def enableProguardInReleaseBuilds = true +/** + * 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 28 @@ -132,6 +141,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 +154,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 c7d08bf4cd53d0..40c8848e0bb863 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 71ebb4a3a3d4df..54ff355be88c1a 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,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 76b157e53c58b5..48a0f33b03b542 100644 --- a/template/android/app/build.gradle +++ b/template/android/app/build.gradle @@ -93,6 +93,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 @@ -149,11 +158,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 4b628a5d57801e..50bbd4ac49d59f 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" From 93a558c8a66b18c7cbf5e9d4b800008ff96bfd47 Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Wed, 3 Apr 2019 10:38:59 -0700 Subject: [PATCH 2/2] Update build.gradle --- RNTester/android/app/build.gradle | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/RNTester/android/app/build.gradle b/RNTester/android/app/build.gradle index 8166b96ce44db5..3ef02339fa931a 100644 --- a/RNTester/android/app/build.gradle +++ b/RNTester/android/app/build.gradle @@ -92,11 +92,10 @@ def enableSeparateBuildPerCPUArchitecture = true def enableProguardInReleaseBuilds = true /** - * 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. + * 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