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
This commit is contained in:
Kudo Chien 2019-04-04 14:12:44 -07:00 коммит произвёл Facebook Github Bot
Родитель 84a1cacfa5
Коммит 8e375850de
9 изменённых файлов: 67 добавлений и 18 удалений

Просмотреть файл

@ -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:+'
}
}

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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

Просмотреть файл

@ -21,6 +21,10 @@ buildscript {
allprojects {
repositories {
mavenLocal()
maven {
url("$rootDir/node_modules/jsc-android/dist")
}
google()
jcenter()

Просмотреть файл

@ -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",

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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()
}
}

Просмотреть файл

@ -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"