Skip to content

Commit

Permalink
Use node package dependency to manage JSC version (facebook#24276)
Browse files Browse the repository at this point in the history
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: facebook#24276

Differential Revision: D14752359

Pulled By: cpojer

fbshipit-source-id: a4bfb135ad8e328f404a2d1a062412f40ebf4622
  • Loading branch information
Kudo authored and zhongwuzw committed Apr 9, 2019
1 parent a6b548c commit 0f20473
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 18 deletions.
20 changes: 20 additions & 0 deletions RNTester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -132,11 +140,23 @@ 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 {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// Build React Native from source
implementation project(':ReactAndroid')

if (useIntlJsc) {
implementation 'org.webkit:android-jsc-intl:+'
} else {
implementation 'org.webkit:android-jsc:+'
}
}
18 changes: 5 additions & 13 deletions ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -168,7 +161,6 @@ task downloadNdkBuildDependencies {
dependsOn(downloadDoubleConversion)
dependsOn(downloadFolly)
dependsOn(downloadGlog)
dependsOn(downloadJSC)
}

def getNdkBuildName() {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion ReactAndroid/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ buildscript {
allprojects {
repositories {
mavenLocal()
maven {
url("$rootDir/node_modules/jsc-android/dist")
}

google()
jcenter()

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scripts/circleci/gradle_download_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions template/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions template/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0f20473

Please sign in to comment.