Skip to content

Commit fcbfde1

Browse files
DanielZlotinfacebook-github-bot
authored andcommitted
Use new JavaScriptCore from npm (#22231)
Summary: Pull Request resolved: #22231 - Use clang instead of the deprecated gcc - Use libc++ instead of the deprecated gnustl - Updated gradle and android plugin version - Fixed missing arch in local-cli template - `clean` task should now always succeed - `clean` task deletes build artifacts - No need to specify buildToolsVersion. It's derived. - Elvis operator for more readable code Pull Request resolved: #22263 Differential Revision: D13004499 fbshipit-source-id: b4eca5d76482539c2c91833801b534e90cf153eb
1 parent f2894e5 commit fcbfde1

17 files changed

Lines changed: 113 additions & 94 deletions

File tree

RNTester/android/app/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def enableProguardInReleaseBuilds = true
9292

9393
android {
9494
compileSdkVersion 27
95-
buildToolsVersion "27.0.3"
9695

9796
defaultConfig {
9897
applicationId "com.facebook.react.uiapp"

ReactAndroid/build.gradle

Lines changed: 86 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins {
1212
import de.undercouch.gradle.tasks.download.Download
1313
import org.apache.tools.ant.taskdefs.condition.Os
1414
import org.apache.tools.ant.filters.ReplaceTokens
15+
import groovy.json.JsonSlurper
1516

1617
// We download various C++ open-source dependencies into downloads.
1718
// We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk.
@@ -68,7 +69,7 @@ task prepareDoubleConversion(dependsOn: dependenciesPath ? [] : [downloadDoubleC
6869
from dependenciesPath ?: tarTree(downloadDoubleConversion.dest)
6970
from 'src/main/jni/third-party/double-conversion/Android.mk'
7071
include "double-conversion-${DOUBLE_CONVERSION_VERSION}/src/**/*", 'Android.mk'
71-
filesMatching('*/src/**/*', {fname -> fname.path = "double-conversion/${fname.name}"})
72+
filesMatching('*/src/**/*', { fname -> fname.path = "double-conversion/${fname.name}" })
7273
includeEmptyDirs = false
7374
into "$thirdPartyNdkDir/double-conversion"
7475
}
@@ -84,17 +85,17 @@ task prepareFolly(dependsOn: dependenciesPath ? [] : [downloadFolly], type: Copy
8485
from dependenciesPath ?: tarTree(downloadFolly.dest)
8586
from 'src/main/jni/third-party/folly/Android.mk'
8687
include "folly-${FOLLY_VERSION}/folly/**/*", 'Android.mk'
87-
eachFile {fname -> fname.path = (fname.path - "folly-${FOLLY_VERSION}/")}
88+
eachFile { fname -> fname.path = (fname.path - "folly-${FOLLY_VERSION}/") }
8889
includeEmptyDirs = false
8990

9091
// Patch for folly build break on gcc 4.9 and could be removed after build by clang
9192
filesMatching('**/container/detail/F14Policy.h') {
9293
filter(ReplaceTokens, tokens: [
93-
'ObjectHolder(Args&&... args) : value_{std::forward<Args>(args)...} {}': 'ObjectHolder(Args&&... args) : value_({std::forward<Args>(args)...}) {}',
94-
'ObjectHolder(Args&&... args) : T{std::forward<Args>(args)...} {}': 'ObjectHolder(Args&&... args) : T({std::forward<Args>(args)...}) {}',
94+
'ObjectHolder(Args&&... args) : value_{std::forward<Args>(args)...} {}': 'ObjectHolder(Args&&... args) : value_({std::forward<Args>(args)...}) {}',
95+
'ObjectHolder(Args&&... args) : T{std::forward<Args>(args)...} {}' : 'ObjectHolder(Args&&... args) : T({std::forward<Args>(args)...}) {}',
9596
],
96-
beginToken: '',
97-
endToken: '')
97+
beginToken: '',
98+
endToken: '')
9899
}
99100

100101
into "$thirdPartyNdkDir/folly"
@@ -116,20 +117,20 @@ task prepareGlog(dependsOn: dependenciesPath ? [] : [downloadGlog], type: Copy)
116117
includeEmptyDirs = false
117118
filesMatching('**/*.h.in') {
118119
filter(ReplaceTokens, tokens: [
119-
ac_cv_have_unistd_h: '1',
120-
ac_cv_have_stdint_h: '1',
121-
ac_cv_have_systypes_h: '1',
122-
ac_cv_have_inttypes_h: '1',
123-
ac_cv_have_libgflags: '0',
124-
ac_google_start_namespace: 'namespace google {',
125-
ac_cv_have_uint16_t: '1',
126-
ac_cv_have_u_int16_t: '1',
127-
ac_cv_have___uint16: '0',
128-
ac_google_end_namespace: '}',
129-
ac_cv_have___builtin_expect: '1',
130-
ac_google_namespace: 'google',
131-
ac_cv___attribute___noinline: '__attribute__ ((noinline))',
132-
ac_cv___attribute___noreturn: '__attribute__ ((noreturn))',
120+
ac_cv_have_unistd_h : '1',
121+
ac_cv_have_stdint_h : '1',
122+
ac_cv_have_systypes_h : '1',
123+
ac_cv_have_inttypes_h : '1',
124+
ac_cv_have_libgflags : '0',
125+
ac_google_start_namespace : 'namespace google {',
126+
ac_cv_have_uint16_t : '1',
127+
ac_cv_have_u_int16_t : '1',
128+
ac_cv_have___uint16 : '0',
129+
ac_google_end_namespace : '}',
130+
ac_cv_have___builtin_expect : '1',
131+
ac_google_namespace : 'google',
132+
ac_cv___attribute___noinline : '__attribute__ ((noinline))',
133+
ac_cv___attribute___noreturn : '__attribute__ ((noreturn))',
133134
ac_cv___attribute___printf_4_5: '__attribute__((__format__ (__printf__, 4, 5)))'
134135
])
135136
it.path = (it.name - '.in')
@@ -145,40 +146,61 @@ task prepareGlog(dependsOn: dependenciesPath ? [] : [downloadGlog], type: Copy)
145146
}
146147
}
147148

148-
task downloadJSCHeaders(type: Download) {
149-
// in sync with webkit SVN revision 174650
150-
def jscAPIBaseURL = 'https://raw.githubusercontent.com/WebKit/webkit/38b15a3ba3c1b0798f2036f7cea36ffdc096202e/Source/JavaScriptCore/API/'
151-
def jscHeaderFiles = ['JavaScript.h', 'JSBase.h', 'JSContextRef.h', 'JSObjectRef.h', 'JSStringRef.h', 'JSValueRef.h', 'WebKitAvailability.h']
152-
def output = new File(downloadsDir, 'jsc')
153-
output.mkdirs()
154-
src(jscHeaderFiles.collect { headerName -> "$jscAPIBaseURL$headerName" })
149+
def readFromCommandLine(String cmd) {
150+
new ByteArrayOutputStream().withStream { os ->
151+
exec {
152+
standardOutput os
153+
commandLine cmd.split(" ")
154+
}.assertNormalExitValue()
155+
return os.toString().trim()
156+
}
157+
}
158+
159+
def isIdeBuild() {
160+
return project.properties['android.injected.invoked.from.ide'] == 'true'
161+
}
162+
163+
task downloadJSC(dependsOn: createNativeDepsDirectories, type: Download) {
164+
if (isIdeBuild()) return
165+
166+
def packageJson = new JsonSlurper().parse(file("${rootDir}/package.json"))
167+
def jscVersionName = packageJson.devDependencies["jsc-android"]
168+
def jscVersion = readFromCommandLine("npm info jsc-android@$jscVersionName version")
169+
def url = readFromCommandLine("npm info jsc-android@$jscVersionName dist.tarball")
170+
src "$url"
155171
onlyIfNewer true
156172
overwrite false
157-
dest output
173+
dest new File(downloadsDir, "jsc-${jscVersion}.tar.gz")
158174
}
159175

160-
// Create Android.mk library module based on so files from mvn + include headers fetched from webkit.org
161-
task prepareJSC(dependsOn: dependenciesPath ? [] : [downloadJSCHeaders]) {
162-
doLast {
163-
copy {
164-
from zipTree(configurations.compile.fileCollection { dep -> dep.name == 'android-jsc' }.singleFile)
165-
from dependenciesPath ? "$dependenciesPath/jsc-headers" : {downloadJSCHeaders.dest}
166-
from 'src/main/jni/third-party/jsc'
167-
include 'jni/**/*.so', '*.h', 'Android.mk'
168-
filesMatching('*.h', { fname -> fname.path = "JavaScriptCore/${fname.path}"})
169-
into "$thirdPartyNdkDir/jsc";
170-
}
176+
// Create Android.mk library module based on jsc from npm
177+
task prepareJSC(dependsOn: downloadJSC) << {
178+
copy {
179+
def jscTar = tarTree(downloadJSC.dest)
180+
def jscAAR = jscTar.matching({ it.include "**/android-jsc/**/*.aar" }).singleFile
181+
def soFiles = zipTree(jscAAR).matching({ it.include "**/*.so" })
182+
183+
def headerFiles = jscTar.matching({ it.include "**/include/*.h" })
184+
185+
from soFiles
186+
from headerFiles
187+
from "src/main/jni/third-party/jsc/Android.mk"
188+
189+
filesMatching("**/*.h", { it.path = "JavaScriptCore/${it.name}"})
190+
191+
includeEmptyDirs false
192+
into "$thirdPartyNdkDir/jsc"
171193
}
172194
}
173195

174196
task downloadNdkBuildDependencies {
175-
if (!boostPath) {
176-
dependsOn downloadBoost
177-
}
178-
dependsOn downloadDoubleConversion
179-
dependsOn downloadFolly
180-
dependsOn downloadGlog
181-
dependsOn downloadJSCHeaders
197+
if (!boostPath) {
198+
dependsOn downloadBoost
199+
}
200+
dependsOn downloadDoubleConversion
201+
dependsOn downloadFolly
202+
dependsOn downloadGlog
203+
dependsOn downloadJSC
182204
}
183205

184206
def getNdkBuildName() {
@@ -217,23 +239,23 @@ def getNdkBuildFullPath() {
217239
def ndkBuildFullPath = findNdkBuildFullPath()
218240
if (ndkBuildFullPath == null) {
219241
throw new GradleScriptException(
220-
"ndk-build binary cannot be found, check if you've set " +
221-
"\$ANDROID_NDK environment variable correctly or if ndk.dir is " +
222-
"setup in local.properties",
223-
null)
242+
"ndk-build binary cannot be found, check if you've set " +
243+
"\$ANDROID_NDK environment variable correctly or if ndk.dir is " +
244+
"setup in local.properties",
245+
null)
224246
}
225247
if (!new File(ndkBuildFullPath).canExecute()) {
226248
throw new GradleScriptException(
227-
"ndk-build binary " + ndkBuildFullPath + " doesn't exist or isn't executable.\n" +
228-
"Check that the \$ANDROID_NDK environment variable, or ndk.dir in local.properties, is set correctly.\n" +
229-
"(On Windows, make sure you escape backslashes in local.properties or use forward slashes, e.g. C:\\\\ndk or C:/ndk rather than C:\\ndk)",
230-
null)
249+
"ndk-build binary " + ndkBuildFullPath + " doesn't exist or isn't executable.\n" +
250+
"Check that the \$ANDROID_NDK environment variable, or ndk.dir in local.properties, is set correctly.\n" +
251+
"(On Windows, make sure you escape backslashes in local.properties or use forward slashes, e.g. C:\\\\ndk or C:/ndk rather than C:\\ndk)",
252+
null)
231253
}
232254
return ndkBuildFullPath
233255
}
234256

235257
task buildReactNdkLib(dependsOn: [prepareJSC, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog], type: Exec) {
236-
inputs.dir('src/main/jni/react')
258+
inputs.file('src/main/jni/react')
237259
outputs.dir("$buildDir/react-ndk/all")
238260
commandLine getNdkBuildFullPath(),
239261
'NDK_PROJECT_PATH=null',
@@ -244,21 +266,27 @@ task buildReactNdkLib(dependsOn: [prepareJSC, prepareBoost, prepareDoubleConvers
244266
"REACT_COMMON_DIR=$projectDir/../ReactCommon",
245267
"REACT_SRC_DIR=$projectDir/src/main/java/com/facebook/react",
246268
'-C', file('src/main/jni/react/jni').absolutePath,
247-
'--jobs', project.hasProperty("jobs") ? project.property("jobs") : Runtime.runtime.availableProcessors()
269+
'--jobs', project.findProperty("jobs") ?: Runtime.runtime.availableProcessors()
248270
}
249271

250272
task cleanReactNdkLib(type: Exec) {
273+
ignoreExitValue true
274+
errorOutput new ByteArrayOutputStream()
251275
commandLine getNdkBuildFullPath(),
252276
"NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
253277
"THIRD_PARTY_NDK_DIR=$buildDir/third-party-ndk",
254278
"REACT_COMMON_DIR=$projectDir/../ReactCommon",
255279
'-C', file('src/main/jni/react/jni').absolutePath,
256280
'clean'
281+
doLast {
282+
file(AAR_OUTPUT_URL).delete()
283+
println "Deleted aar output dir at ${file(AAR_OUTPUT_URL)}"
284+
}
257285
}
258286

259287
task packageReactNdkLibs(dependsOn: buildReactNdkLib, type: Copy) {
260288
from "$buildDir/react-ndk/all"
261-
exclude '**/libjsc.so'
289+
from "$thirdPartyNdkDir/jsc/jni"
262290
into "$buildDir/react-ndk/exported"
263291
}
264292

@@ -269,7 +297,6 @@ task packageReactNdkLibsForBuck(dependsOn: packageReactNdkLibs, type: Copy) {
269297

270298
android {
271299
compileSdkVersion 27
272-
buildToolsVersion "27.0.3"
273300

274301
defaultConfig {
275302
minSdkVersion 16
@@ -291,7 +318,7 @@ android {
291318

292319
sourceSets.main {
293320
jni.srcDirs = []
294-
jniLibs.srcDirs = ["$buildDir/react-ndk/exported", 'src/main/jni/third-party/jsc/jni']
321+
jniLibs.srcDir "$buildDir/react-ndk/exported"
295322
res.srcDirs = ['src/main/res/devsupport', 'src/main/res/shell', 'src/main/res/views/modal', 'src/main/res/views/uimanager']
296323
java {
297324
srcDirs = ['src/main/java', 'src/main/libraries/soloader/java', 'src/main/jni/first-party/fb/jni/java']
@@ -326,7 +353,6 @@ dependencies {
326353
api "com.squareup.okhttp3:okhttp:${OKHTTP_VERSION}"
327354
api "com.squareup.okhttp3:okhttp-urlconnection:${OKHTTP_VERSION}"
328355
api 'com.squareup.okio:okio:1.14.0'
329-
compile 'org.webkit:android-jsc:r174650'
330356

331357
testImplementation "junit:junit:${JUNIT_VERSION}"
332358
testImplementation "org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}"

ReactAndroid/release.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
apply plugin: 'maven'
77
apply plugin: 'signing'
88

9+
ext {
10+
AAR_OUTPUT_URL = "file://${projectDir}/../android"
11+
}
12+
913
// Gradle tasks for publishing to maven
1014
// 1) To install in local maven repo use :installArchives task
1115
// 2) To upload artifact to maven central use: :uploadArchives (you'd need to have the permission to do that)
@@ -15,15 +19,15 @@ def isReleaseBuild() {
1519
}
1620

1721
def getRepositoryUrl() {
18-
return project.hasProperty('repositoryUrl') ? property('repositoryUrl') : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
22+
return project.findProperty('repositoryUrl') ?: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
1923
}
2024

2125
def getRepositoryUsername() {
22-
return project.hasProperty('repositoryUsername') ? property('repositoryUsername') : ''
26+
return project.findProperty('repositoryUsername') ?: ''
2327
}
2428

2529
def getRepositoryPassword() {
26-
return project.hasProperty('repositoryPassword') ? property('repositoryPassword') : ''
30+
return project.findProperty('repositoryPassword') ?: ''
2731
}
2832

2933
def configureReactNativePom(def pom) {
@@ -128,7 +132,7 @@ afterEvaluate { project ->
128132
configuration = configurations.archives
129133
repositories.mavenDeployer {
130134
// Deploy to react-native/android, ready to publish to npm
131-
repository url: "file://${projectDir}/../android"
135+
repository url: AAR_OUTPUT_URL
132136

133137
configureReactNativePom pom
134138
}

ReactAndroid/src/main/jni/Application.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ APP_MK_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
2424
# etc.) are defined inside build.gradle.
2525
NDK_MODULE_PATH := $(APP_MK_DIR)$(HOST_DIRSEP)$(THIRD_PARTY_NDK_DIR)$(HOST_DIRSEP)$(REACT_COMMON_DIR)$(HOST_DIRSEP)$(APP_MK_DIR)first-party$(HOST_DIRSEP)$(REACT_SRC_DIR)
2626

27-
APP_STL := gnustl_shared
27+
APP_STL := c++_shared
2828

2929
# Make sure every shared lib includes a .note.gnu.build-id header
3030
APP_CFLAGS := -Wall -Werror
3131
APP_CPPFLAGS := -std=c++1y
3232
APP_LDFLAGS := -Wl,--build-id
3333

34-
NDK_TOOLCHAIN_VERSION := 4.9
34+
NDK_TOOLCHAIN_VERSION := clang

ReactAndroid/src/main/jni/react/jni/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)
1717
# ./../ == react
1818
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../..
1919

20-
LOCAL_CFLAGS += -fexceptions -frtti
20+
LOCAL_CFLAGS += -fexceptions -frtti -Wno-unused-lambda-capture
2121

2222
LOCAL_LDLIBS += -landroid
2323

ReactAndroid/src/main/jni/third-party/folly/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ FOLLY_FLAGS := \
2626
-DFOLLY_NO_CONFIG=1 \
2727
-DFOLLY_HAVE_CLOCK_GETTIME=1 \
2828
-DFOLLY_HAVE_MEMRCHR=1 \
29+
-DFOLLY_USE_LIBCPP=1
2930

3031
# If APP_PLATFORM in Application.mk targets android-23 above, please comment this line.
3132
# NDK uses GNU style stderror_r() after API 23.

ReactAndroid/src/main/jni/third-party/glog/Android.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ LOCAL_CFLAGS += \
2323
-g \
2424
-O2 \
2525
-D_START_GOOGLE_NAMESPACE_="namespace google {" \
26-
-D_END_GOOGLE_NAMESPACE_="}"
26+
-D_END_GOOGLE_NAMESPACE_="}" \
27+
-DHAVE_PREAD=1
2728

2829

2930
LOCAL_MODULE := glog

ReactCommon/cxxreact/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
1717
LOCAL_CFLAGS := \
1818
-DLOG_TAG=\"ReactNative\"
1919

20-
LOCAL_CFLAGS += -fexceptions -frtti
20+
LOCAL_CFLAGS += -fexceptions -frtti -Wno-unused-lambda-capture
2121

2222
LOCAL_STATIC_LIBRARIES := boost
2323
LOCAL_SHARED_LIBRARIES := jsinspector libfolly_json glog

build.gradle

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildscript {
1010
jcenter()
1111
}
1212
dependencies {
13-
classpath 'com.android.tools.build:gradle:3.1.4'
13+
classpath 'com.android.tools.build:gradle:3.2.1'
1414
classpath 'de.undercouch:gradle-download-task:3.4.3'
1515

1616
// NOTE: Do not place your application dependencies here; they belong
@@ -30,8 +30,3 @@ allprojects {
3030
}
3131
}
3232
}
33-
34-
task wrapper(type: Wrapper) {
35-
gradleVersion = '4.4'
36-
distributionUrl = distributionUrl.replace("bin", "all")
37-
}

gradle/wrapper/gradle-wrapper.jar

1.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)