2015-09-16 17:38:42 +00:00
|
|
|
// Copyright 2015-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
apply plugin: 'com.android.library'
|
|
|
|
apply plugin: 'maven'
|
|
|
|
|
|
|
|
apply plugin: 'de.undercouch.download'
|
|
|
|
|
|
|
|
import de.undercouch.gradle.tasks.download.Download
|
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
import org.apache.tools.ant.filters.ReplaceTokens
|
|
|
|
|
|
|
|
// We download various C++ open-source dependencies into downloads.
|
2015-09-21 20:30:08 +00:00
|
|
|
// We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk.
|
|
|
|
// After that we build native code from src/main/jni with module path pointing at third-party-ndk.
|
2015-09-16 17:38:42 +00:00
|
|
|
|
2018-03-30 03:59:47 +00:00
|
|
|
def customDownloadsDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
|
|
|
|
def downloadsDir = customDownloadsDir ? new File(customDownloadsDir) : new File("$buildDir/downloads")
|
2015-09-16 17:38:42 +00:00
|
|
|
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
|
|
|
|
|
2016-11-29 22:26:01 +00:00
|
|
|
// You need to have following folders in this directory:
|
2017-05-10 12:57:59 +00:00
|
|
|
// - boost_1_63_0
|
2016-11-29 22:26:01 +00:00
|
|
|
// - double-conversion-1.1.1
|
|
|
|
// - folly-deprecate-dynamic-initializer
|
|
|
|
// - glog-0.3.3
|
|
|
|
// - jsc-headers
|
|
|
|
def dependenciesPath = System.getenv("REACT_NATIVE_DEPENDENCIES")
|
|
|
|
|
2016-04-21 13:47:21 +00:00
|
|
|
// The Boost library is a very large download (>100MB).
|
|
|
|
// If Boost is already present on your system, define the REACT_NATIVE_BOOST_PATH env variable
|
|
|
|
// and the build will use that.
|
2016-11-29 22:26:01 +00:00
|
|
|
def boostPath = dependenciesPath ?: System.getenv("REACT_NATIVE_BOOST_PATH")
|
2016-04-21 13:47:21 +00:00
|
|
|
|
2015-09-16 17:38:42 +00:00
|
|
|
task createNativeDepsDirectories {
|
|
|
|
downloadsDir.mkdirs()
|
|
|
|
thirdPartyNdkDir.mkdirs()
|
|
|
|
}
|
|
|
|
|
|
|
|
task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
|
2017-03-10 13:12:27 +00:00
|
|
|
src 'https://github.com/react-native-community/boost-for-react-native/releases/download/v1.63.0-0/boost_1_63_0.tar.gz'
|
2015-09-16 17:38:42 +00:00
|
|
|
onlyIfNewer true
|
|
|
|
overwrite false
|
2017-03-10 13:12:27 +00:00
|
|
|
dest new File(downloadsDir, 'boost_1_63_0.tar.gz')
|
2015-09-16 17:38:42 +00:00
|
|
|
}
|
|
|
|
|
2016-12-19 21:07:16 +00:00
|
|
|
task prepareBoost(dependsOn: boostPath ? [] : [downloadBoost], type: Copy) {
|
|
|
|
from boostPath ?: tarTree(resources.gzip(downloadBoost.dest))
|
2015-12-14 14:23:06 +00:00
|
|
|
from 'src/main/jni/third-party/boost/Android.mk'
|
2017-05-10 12:57:59 +00:00
|
|
|
include 'Android.mk', 'boost_1_63_0/boost/**/*.hpp', 'boost/boost/**/*.hpp'
|
2016-12-19 21:07:16 +00:00
|
|
|
includeEmptyDirs = false
|
2015-12-14 14:23:06 +00:00
|
|
|
into "$thirdPartyNdkDir/boost"
|
2017-05-10 12:57:59 +00:00
|
|
|
doLast {
|
|
|
|
file("$thirdPartyNdkDir/boost/boost").renameTo("$thirdPartyNdkDir/boost/boost_1_63_0")
|
|
|
|
}
|
2015-09-16 17:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Download) {
|
|
|
|
src 'https://github.com/google/double-conversion/archive/v1.1.1.tar.gz'
|
|
|
|
onlyIfNewer true
|
|
|
|
overwrite false
|
|
|
|
dest new File(downloadsDir, 'double-conversion-1.1.1.tar.gz')
|
|
|
|
}
|
|
|
|
|
2016-11-29 22:26:01 +00:00
|
|
|
task prepareDoubleConversion(dependsOn: dependenciesPath ? [] : [downloadDoubleConversion], type: Copy) {
|
|
|
|
from dependenciesPath ?: tarTree(downloadDoubleConversion.dest)
|
2015-09-16 17:38:42 +00:00
|
|
|
from 'src/main/jni/third-party/double-conversion/Android.mk'
|
|
|
|
include 'double-conversion-1.1.1/src/**/*', 'Android.mk'
|
|
|
|
filesMatching('*/src/**/*', {fname -> fname.path = "double-conversion/${fname.name}"})
|
|
|
|
includeEmptyDirs = false
|
|
|
|
into "$thirdPartyNdkDir/double-conversion"
|
|
|
|
}
|
|
|
|
|
|
|
|
task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) {
|
2016-09-30 22:27:05 +00:00
|
|
|
src 'https://github.com/facebook/folly/archive/v2016.09.26.00.tar.gz'
|
2015-09-16 17:38:42 +00:00
|
|
|
onlyIfNewer true
|
|
|
|
overwrite false
|
2016-09-30 22:27:05 +00:00
|
|
|
dest new File(downloadsDir, 'folly-2016.09.26.00.tar.gz');
|
2015-09-16 17:38:42 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 22:26:01 +00:00
|
|
|
task prepareFolly(dependsOn: dependenciesPath ? [] : [downloadFolly], type: Copy) {
|
|
|
|
from dependenciesPath ?: tarTree(downloadFolly.dest)
|
2015-09-16 17:38:42 +00:00
|
|
|
from 'src/main/jni/third-party/folly/Android.mk'
|
2016-09-30 22:27:05 +00:00
|
|
|
include 'folly-2016.09.26.00/folly/**/*', 'Android.mk'
|
|
|
|
eachFile {fname -> fname.path = (fname.path - "folly-2016.09.26.00/")}
|
2015-09-16 17:38:42 +00:00
|
|
|
includeEmptyDirs = false
|
|
|
|
into "$thirdPartyNdkDir/folly"
|
|
|
|
}
|
|
|
|
|
|
|
|
task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {
|
|
|
|
src 'https://github.com/google/glog/archive/v0.3.3.tar.gz'
|
|
|
|
onlyIfNewer true
|
|
|
|
overwrite false
|
|
|
|
dest new File(downloadsDir, 'glog-0.3.3.tar.gz')
|
|
|
|
}
|
|
|
|
|
2016-04-21 13:47:21 +00:00
|
|
|
// Prepare glog sources to be compiled, this task will perform steps that normally should've been
|
2015-09-16 17:38:42 +00:00
|
|
|
// executed by automake. This way we can avoid dependencies on make/automake
|
2016-11-29 22:26:01 +00:00
|
|
|
task prepareGlog(dependsOn: dependenciesPath ? [] : [downloadGlog], type: Copy) {
|
|
|
|
from dependenciesPath ?: tarTree(downloadGlog.dest)
|
2015-09-16 17:38:42 +00:00
|
|
|
from 'src/main/jni/third-party/glog/'
|
|
|
|
include 'glog-0.3.3/src/**/*', 'Android.mk', 'config.h'
|
|
|
|
includeEmptyDirs = false
|
|
|
|
filesMatching('**/*.h.in') {
|
|
|
|
filter(ReplaceTokens, tokens: [
|
|
|
|
ac_cv_have_unistd_h: '1',
|
|
|
|
ac_cv_have_stdint_h: '1',
|
|
|
|
ac_cv_have_systypes_h: '1',
|
|
|
|
ac_cv_have_inttypes_h: '1',
|
|
|
|
ac_cv_have_libgflags: '0',
|
|
|
|
ac_google_start_namespace: 'namespace google {',
|
|
|
|
ac_cv_have_uint16_t: '1',
|
|
|
|
ac_cv_have_u_int16_t: '1',
|
|
|
|
ac_cv_have___uint16: '0',
|
|
|
|
ac_google_end_namespace: '}',
|
|
|
|
ac_cv_have___builtin_expect: '1',
|
|
|
|
ac_google_namespace: 'google',
|
|
|
|
ac_cv___attribute___noinline: '__attribute__ ((noinline))',
|
|
|
|
ac_cv___attribute___noreturn: '__attribute__ ((noreturn))',
|
|
|
|
ac_cv___attribute___printf_4_5: '__attribute__((__format__ (__printf__, 4, 5)))'
|
|
|
|
])
|
|
|
|
it.path = (it.name - '.in')
|
|
|
|
}
|
|
|
|
into "$thirdPartyNdkDir/glog"
|
|
|
|
}
|
|
|
|
|
|
|
|
task downloadJSCHeaders(type: Download) {
|
2016-12-19 21:07:16 +00:00
|
|
|
// in sync with webkit SVN revision 174650
|
|
|
|
def jscAPIBaseURL = 'https://raw.githubusercontent.com/WebKit/webkit/38b15a3ba3c1b0798f2036f7cea36ffdc096202e/Source/JavaScriptCore/API/'
|
2016-05-27 23:02:50 +00:00
|
|
|
def jscHeaderFiles = ['JavaScript.h', 'JSBase.h', 'JSContextRef.h', 'JSObjectRef.h', 'JSRetainPtr.h', 'JSStringRef.h', 'JSValueRef.h', 'WebKitAvailability.h']
|
2015-09-16 17:38:42 +00:00
|
|
|
def output = new File(downloadsDir, 'jsc')
|
|
|
|
output.mkdirs()
|
|
|
|
src(jscHeaderFiles.collect { headerName -> "$jscAPIBaseURL$headerName" })
|
|
|
|
onlyIfNewer true
|
|
|
|
overwrite false
|
|
|
|
dest output
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Android.mk library module based on so files from mvn + include headers fetched from webkit.org
|
2016-11-29 22:26:01 +00:00
|
|
|
task prepareJSC(dependsOn: dependenciesPath ? [] : [downloadJSCHeaders]) << {
|
2015-09-16 17:38:42 +00:00
|
|
|
copy {
|
|
|
|
from zipTree(configurations.compile.fileCollection { dep -> dep.name == 'android-jsc' }.singleFile)
|
2016-11-29 22:26:01 +00:00
|
|
|
from dependenciesPath ? "$dependenciesPath/jsc-headers" : {downloadJSCHeaders.dest}
|
2015-09-16 17:38:42 +00:00
|
|
|
from 'src/main/jni/third-party/jsc/Android.mk'
|
|
|
|
include 'jni/**/*.so', '*.h', 'Android.mk'
|
|
|
|
filesMatching('*.h', { fname -> fname.path = "JavaScriptCore/${fname.path}"})
|
|
|
|
into "$thirdPartyNdkDir/jsc";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-30 03:59:47 +00:00
|
|
|
task downloadNdkBuildDependencies {
|
|
|
|
if (!boostPath) {
|
|
|
|
dependsOn downloadBoost
|
|
|
|
}
|
|
|
|
dependsOn downloadDoubleConversion
|
|
|
|
dependsOn downloadFolly
|
|
|
|
dependsOn downloadGlog
|
|
|
|
dependsOn downloadJSCHeaders
|
|
|
|
}
|
|
|
|
|
2015-09-16 17:38:42 +00:00
|
|
|
def getNdkBuildName() {
|
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
return "ndk-build.cmd"
|
|
|
|
} else {
|
|
|
|
return "ndk-build"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def findNdkBuildFullPath() {
|
|
|
|
// we allow to provide full path to ndk-build tool
|
|
|
|
if (hasProperty('ndk.command')) {
|
|
|
|
return property('ndk.command')
|
|
|
|
}
|
|
|
|
// or just a path to the containing directory
|
|
|
|
if (hasProperty('ndk.path')) {
|
|
|
|
def ndkDir = property('ndk.path')
|
|
|
|
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
|
|
|
|
}
|
|
|
|
if (System.getenv('ANDROID_NDK') != null) {
|
|
|
|
def ndkDir = System.getenv('ANDROID_NDK')
|
|
|
|
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
|
|
|
|
}
|
|
|
|
def ndkDir = android.hasProperty('plugin') ? android.plugin.ndkFolder :
|
2017-06-27 03:50:23 +00:00
|
|
|
plugins.getPlugin('com.android.library').hasProperty('sdkHandler') ?
|
|
|
|
plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder() :
|
|
|
|
android.ndkDirectory.absolutePath
|
2015-09-16 17:38:42 +00:00
|
|
|
if (ndkDir) {
|
|
|
|
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
def getNdkBuildFullPath() {
|
|
|
|
def ndkBuildFullPath = findNdkBuildFullPath()
|
2015-09-23 12:55:42 +00:00
|
|
|
if (ndkBuildFullPath == null) {
|
2015-09-16 17:38:42 +00:00
|
|
|
throw new GradleScriptException(
|
|
|
|
"ndk-build binary cannot be found, check if you've set " +
|
|
|
|
"\$ANDROID_NDK environment variable correctly or if ndk.dir is " +
|
|
|
|
"setup in local.properties",
|
|
|
|
null)
|
|
|
|
}
|
2015-09-23 12:55:42 +00:00
|
|
|
if (!new File(ndkBuildFullPath).canExecute()) {
|
|
|
|
throw new GradleScriptException(
|
|
|
|
"ndk-build binary " + ndkBuildFullPath + " doesn't exist or isn't executable.\n" +
|
2017-06-11 07:13:04 +00:00
|
|
|
"Check that the \$ANDROID_NDK environment variable, or ndk.dir in local.properties, is set correctly.\n" +
|
2015-09-23 12:55:42 +00:00
|
|
|
"(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)",
|
|
|
|
null)
|
|
|
|
}
|
2015-09-16 17:38:42 +00:00
|
|
|
return ndkBuildFullPath
|
|
|
|
}
|
|
|
|
|
|
|
|
task buildReactNdkLib(dependsOn: [prepareJSC, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog], type: Exec) {
|
2017-06-01 12:30:34 +00:00
|
|
|
inputs.file('src/main/jni/react')
|
2015-09-16 17:38:42 +00:00
|
|
|
outputs.dir("$buildDir/react-ndk/all")
|
|
|
|
commandLine getNdkBuildFullPath(),
|
|
|
|
'NDK_PROJECT_PATH=null',
|
|
|
|
"NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
|
|
|
|
'NDK_OUT=' + temporaryDir,
|
|
|
|
"NDK_LIBS_OUT=$buildDir/react-ndk/all",
|
|
|
|
"THIRD_PARTY_NDK_DIR=$buildDir/third-party-ndk",
|
2016-05-27 23:02:50 +00:00
|
|
|
"REACT_COMMON_DIR=$projectDir/../ReactCommon",
|
2016-06-14 01:35:20 +00:00
|
|
|
'-C', file('src/main/jni/react/jni').absolutePath,
|
2015-12-24 18:39:19 +00:00
|
|
|
'--jobs', project.hasProperty("jobs") ? project.property("jobs") : Runtime.runtime.availableProcessors()
|
2015-09-16 17:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
task cleanReactNdkLib(type: Exec) {
|
|
|
|
commandLine getNdkBuildFullPath(),
|
2016-07-30 00:55:15 +00:00
|
|
|
"NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
|
|
|
|
"THIRD_PARTY_NDK_DIR=$buildDir/third-party-ndk",
|
2016-08-27 00:08:21 +00:00
|
|
|
"REACT_COMMON_DIR=$projectDir/../ReactCommon",
|
2015-09-16 17:38:42 +00:00
|
|
|
'-C', file('src/main/jni/react/jni').absolutePath,
|
|
|
|
'clean'
|
|
|
|
}
|
|
|
|
|
|
|
|
task packageReactNdkLibs(dependsOn: buildReactNdkLib, type: Copy) {
|
|
|
|
from "$buildDir/react-ndk/all"
|
|
|
|
exclude '**/libjsc.so'
|
|
|
|
into "$buildDir/react-ndk/exported"
|
|
|
|
}
|
|
|
|
|
2016-02-26 00:39:29 +00:00
|
|
|
task packageReactNdkLibsForBuck(dependsOn: packageReactNdkLibs, type: Copy) {
|
2016-10-19 23:50:39 +00:00
|
|
|
from "$buildDir/react-ndk/exported"
|
|
|
|
into "src/main/jni/prebuilt/lib"
|
2016-02-26 00:39:29 +00:00
|
|
|
}
|
|
|
|
|
2015-09-16 17:38:42 +00:00
|
|
|
android {
|
2015-09-17 13:33:23 +00:00
|
|
|
compileSdkVersion 23
|
|
|
|
buildToolsVersion "23.0.1"
|
2015-09-16 17:38:42 +00:00
|
|
|
|
|
|
|
defaultConfig {
|
|
|
|
minSdkVersion 16
|
|
|
|
targetSdkVersion 22
|
|
|
|
versionCode 1
|
|
|
|
versionName "1.0"
|
|
|
|
|
2018-04-06 00:26:39 +00:00
|
|
|
consumerProguardFiles 'proguard-rules.pro'
|
|
|
|
|
2015-09-16 17:38:42 +00:00
|
|
|
ndk {
|
|
|
|
moduleName "reactnativejni"
|
|
|
|
}
|
|
|
|
|
|
|
|
buildConfigField 'boolean', 'IS_INTERNAL_BUILD', 'false'
|
2016-04-27 15:01:54 +00:00
|
|
|
buildConfigField 'int', 'EXOPACKAGE_FLAGS', '0'
|
2016-03-02 14:55:09 +00:00
|
|
|
testApplicationId "com.facebook.react.tests.gradle"
|
2015-12-21 17:37:27 +00:00
|
|
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
2015-09-16 17:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sourceSets.main {
|
|
|
|
jni.srcDirs = []
|
|
|
|
jniLibs.srcDir "$buildDir/react-ndk/exported"
|
2017-04-05 19:19:50 +00:00
|
|
|
res.srcDirs = ['src/main/res/devsupport', 'src/main/res/shell', 'src/main/res/views/modal', 'src/main/res/views/uimanager']
|
2016-01-07 11:51:28 +00:00
|
|
|
java {
|
2016-10-19 23:50:39 +00:00
|
|
|
srcDirs = ['src/main/java', 'src/main/libraries/soloader/java', 'src/main/jni/first-party/fb/jni/java']
|
|
|
|
exclude 'com/facebook/react/processing'
|
|
|
|
exclude 'com/facebook/react/module/processing'
|
2016-01-07 11:51:28 +00:00
|
|
|
}
|
2015-09-16 17:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tasks.withType(JavaCompile) {
|
|
|
|
compileTask -> compileTask.dependsOn packageReactNdkLibs
|
|
|
|
}
|
|
|
|
|
|
|
|
clean.dependsOn cleanReactNdkLib
|
|
|
|
|
|
|
|
lintOptions {
|
|
|
|
abortOnError false
|
|
|
|
}
|
2016-06-16 11:04:34 +00:00
|
|
|
packagingOptions {
|
|
|
|
exclude 'META-INF/NOTICE'
|
|
|
|
exclude 'META-INF/LICENSE'
|
|
|
|
}
|
2015-09-16 17:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2016-01-18 20:37:59 +00:00
|
|
|
compile fileTree(dir: 'src/main/third-party/java/infer-annotations/', include: ['*.jar'])
|
2016-08-11 00:12:35 +00:00
|
|
|
compile 'javax.inject:javax.inject:1'
|
2015-09-17 13:33:23 +00:00
|
|
|
compile 'com.android.support:appcompat-v7:23.0.1'
|
2016-12-19 21:41:07 +00:00
|
|
|
compile 'com.facebook.fbui.textlayoutbuilder:textlayoutbuilder:1.0.0'
|
2018-03-22 01:07:47 +00:00
|
|
|
compile 'com.facebook.fresco:fresco:1.8.1'
|
|
|
|
compile 'com.facebook.fresco:imagepipeline-okhttp3:1.8.1'
|
|
|
|
compile 'com.facebook.soloader:soloader:0.3.0'
|
2015-09-16 17:38:42 +00:00
|
|
|
compile 'com.google.code.findbugs:jsr305:3.0.0'
|
2018-03-22 01:07:47 +00:00
|
|
|
compile 'com.squareup.okhttp3:okhttp:3.8.0'
|
|
|
|
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.8.0'
|
2018-03-29 18:02:04 +00:00
|
|
|
compile 'com.squareup.okio:okio:1.14.0'
|
2015-09-16 17:38:42 +00:00
|
|
|
compile 'org.webkit:android-jsc:r174650'
|
2015-11-27 11:57:38 +00:00
|
|
|
|
|
|
|
testCompile "junit:junit:${JUNIT_VERSION}"
|
|
|
|
testCompile "org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}"
|
|
|
|
testCompile "org.powermock:powermock-module-junit4-rule:${POWERMOCK_VERSION}"
|
|
|
|
testCompile "org.powermock:powermock-classloading-xstream:${POWERMOCK_VERSION}"
|
|
|
|
testCompile "org.mockito:mockito-core:${MOCKITO_CORE_VERSION}"
|
|
|
|
testCompile "org.easytesting:fest-assert-core:${FEST_ASSERT_CORE_VERSION}"
|
2015-12-17 19:09:22 +00:00
|
|
|
testCompile "org.robolectric:robolectric:${ROBOLECTRIC_VERSION}"
|
2018-03-29 18:02:04 +00:00
|
|
|
|
2016-08-19 13:57:41 +00:00
|
|
|
androidTestCompile fileTree(dir: 'src/main/third-party/java/buck-android-support/', include: ['*.jar'])
|
2016-04-14 14:49:19 +00:00
|
|
|
androidTestCompile 'com.android.support.test:runner:0.3'
|
2016-06-16 11:04:34 +00:00
|
|
|
androidTestCompile "org.mockito:mockito-core:${MOCKITO_CORE_VERSION}"
|
2015-09-16 17:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
apply from: 'release.gradle'
|