2019-10-16 20:03:47 +03:00
|
|
|
/*
|
2021-12-31 02:08:43 +03:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2019-10-16 20:03:47 +03:00
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
2015-09-16 20:38:42 +03:00
|
|
|
|
2018-09-14 01:35:32 +03:00
|
|
|
plugins {
|
|
|
|
id("com.android.library")
|
2021-09-15 13:19:56 +03:00
|
|
|
id("com.facebook.react")
|
2021-06-04 00:27:58 +03:00
|
|
|
id("maven-publish")
|
2019-05-15 13:25:38 +03:00
|
|
|
id("de.undercouch.download")
|
2018-09-14 01:35:32 +03:00
|
|
|
}
|
2015-09-16 20:38:42 +03:00
|
|
|
|
2021-10-18 14:32:45 +03:00
|
|
|
import com.facebook.react.tasks.internal.*
|
|
|
|
|
2019-10-14 09:24:59 +03:00
|
|
|
import java.nio.file.Paths
|
|
|
|
|
2015-09-16 20:38:42 +03:00
|
|
|
import de.undercouch.gradle.tasks.download.Download
|
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
import org.apache.tools.ant.filters.ReplaceTokens
|
|
|
|
|
2021-06-04 00:27:58 +03:00
|
|
|
def AAR_OUTPUT_URL = "file://${projectDir}/../android"
|
2015-09-16 20:38:42 +03:00
|
|
|
// We download various C++ open-source dependencies into downloads.
|
2015-09-21 23:30:08 +03: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 20:38:42 +03:00
|
|
|
|
2018-03-30 06:59:47 +03:00
|
|
|
def customDownloadsDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
|
|
|
|
def downloadsDir = customDownloadsDir ? new File(customDownloadsDir) : new File("$buildDir/downloads")
|
2015-09-16 20:38:42 +03:00
|
|
|
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
|
|
|
|
|
2016-11-30 01:26:01 +03:00
|
|
|
// You need to have following folders in this directory:
|
2017-05-10 15:57:59 +03:00
|
|
|
// - boost_1_63_0
|
2018-06-27 21:42:53 +03:00
|
|
|
// - double-conversion-1.1.6
|
2016-11-30 01:26:01 +03:00
|
|
|
// - folly-deprecate-dynamic-initializer
|
2018-06-27 21:57:41 +03:00
|
|
|
// - glog-0.3.5
|
2016-11-30 01:26:01 +03:00
|
|
|
def dependenciesPath = System.getenv("REACT_NATIVE_DEPENDENCIES")
|
|
|
|
|
2016-04-21 16:47:21 +03: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-30 01:26:01 +03:00
|
|
|
def boostPath = dependenciesPath ?: System.getenv("REACT_NATIVE_BOOST_PATH")
|
2016-04-21 16:47:21 +03:00
|
|
|
|
2019-06-04 22:39:41 +03:00
|
|
|
// Setup build type for NDK, supported values: {debug, release}
|
|
|
|
def nativeBuildType = System.getenv("NATIVE_BUILD_TYPE") ?: "release"
|
|
|
|
|
2015-09-16 20:38:42 +03:00
|
|
|
task createNativeDepsDirectories {
|
|
|
|
downloadsDir.mkdirs()
|
|
|
|
thirdPartyNdkDir.mkdirs()
|
|
|
|
}
|
|
|
|
|
|
|
|
task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
|
2019-02-09 21:14:55 +03:00
|
|
|
src("https://github.com/react-native-community/boost-for-react-native/releases/download/v${BOOST_VERSION.replace("_", ".")}-0/boost_${BOOST_VERSION}.tar.gz")
|
|
|
|
onlyIfNewer(true)
|
|
|
|
overwrite(false)
|
|
|
|
dest(new File(downloadsDir, "boost_${BOOST_VERSION}.tar.gz"))
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
2021-10-18 14:32:45 +03:00
|
|
|
final def prepareBoost = tasks.register("prepareBoost", PrepareBoostTask) {
|
|
|
|
it.dependsOn(boostPath ? [] : [downloadBoost])
|
|
|
|
it.boostPath.setFrom(boostPath ?: tarTree(resources.gzip(downloadBoost.dest)))
|
|
|
|
it.boostVersion.set(BOOST_VERSION)
|
|
|
|
it.outputDir.set(new File(thirdPartyNdkDir, "boost"))
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Download) {
|
2019-02-09 21:14:55 +03:00
|
|
|
src("https://github.com/google/double-conversion/archive/v${DOUBLE_CONVERSION_VERSION}.tar.gz")
|
|
|
|
onlyIfNewer(true)
|
|
|
|
overwrite(false)
|
|
|
|
dest(new File(downloadsDir, "double-conversion-${DOUBLE_CONVERSION_VERSION}.tar.gz"))
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
2016-11-30 01:26:01 +03:00
|
|
|
task prepareDoubleConversion(dependsOn: dependenciesPath ? [] : [downloadDoubleConversion], type: Copy) {
|
2019-02-09 21:14:55 +03:00
|
|
|
from(dependenciesPath ?: tarTree(downloadDoubleConversion.dest))
|
|
|
|
from("src/main/jni/third-party/double-conversion/Android.mk")
|
|
|
|
include("double-conversion-${DOUBLE_CONVERSION_VERSION}/src/**/*", "Android.mk")
|
|
|
|
filesMatching("*/src/**/*", { fname -> fname.path = "double-conversion/${fname.name}" })
|
2015-09-16 20:38:42 +03:00
|
|
|
includeEmptyDirs = false
|
2019-02-09 21:14:55 +03:00
|
|
|
into("$thirdPartyNdkDir/double-conversion")
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) {
|
2019-02-09 21:14:55 +03:00
|
|
|
src("https://github.com/facebook/folly/archive/v${FOLLY_VERSION}.tar.gz")
|
|
|
|
onlyIfNewer(true)
|
|
|
|
overwrite(false)
|
|
|
|
dest(new File(downloadsDir, "folly-${FOLLY_VERSION}.tar.gz"))
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
2016-11-30 01:26:01 +03:00
|
|
|
task prepareFolly(dependsOn: dependenciesPath ? [] : [downloadFolly], type: Copy) {
|
2019-02-09 21:14:55 +03:00
|
|
|
from(dependenciesPath ?: tarTree(downloadFolly.dest))
|
|
|
|
from("src/main/jni/third-party/folly/Android.mk")
|
|
|
|
include("folly-${FOLLY_VERSION}/folly/**/*", "Android.mk")
|
2018-12-28 01:45:36 +03:00
|
|
|
eachFile { fname -> fname.path = (fname.path - "folly-${FOLLY_VERSION}/") }
|
2015-09-16 20:38:42 +03:00
|
|
|
includeEmptyDirs = false
|
2019-02-09 21:14:55 +03:00
|
|
|
into("$thirdPartyNdkDir/folly")
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
2021-05-11 16:02:29 +03:00
|
|
|
task downloadFmt(dependsOn: createNativeDepsDirectories, type: Download) {
|
|
|
|
src("https://github.com/fmtlib/fmt/archive/${FMT_VERSION}.tar.gz")
|
|
|
|
onlyIfNewer(true)
|
|
|
|
overwrite(false)
|
|
|
|
dest(new File(downloadsDir, "fmt-${FMT_VERSION}.tar.gz"))
|
|
|
|
}
|
|
|
|
|
|
|
|
task prepareFmt(dependsOn: dependenciesPath ? [] : [downloadFmt], type: Copy) {
|
|
|
|
from(dependenciesPath ?: tarTree(downloadFmt.dest))
|
|
|
|
from("src/main/jni/third-party/fmt/Android.mk")
|
|
|
|
include("fmt-${FMT_VERSION}/src/**/*", "fmt-${FMT_VERSION}/include/**/*", "Android.mk")
|
|
|
|
eachFile { fname -> fname.path = (fname.path - "fmt-${FMT_VERSION}/") }
|
|
|
|
includeEmptyDirs = false
|
|
|
|
into("$thirdPartyNdkDir/fmt")
|
|
|
|
}
|
|
|
|
|
|
|
|
task downloadLibevent(dependsOn: createNativeDepsDirectories, type: Download) {
|
|
|
|
src("https://github.com/libevent/libevent/releases/download/release-${LIBEVENT_VERSION}-stable/libevent-${LIBEVENT_VERSION}-stable.tar.gz")
|
|
|
|
onlyIfNewer(true)
|
|
|
|
overwrite(false)
|
|
|
|
dest(new File(downloadsDir, "libevent-${LIBEVENT_VERSION}.tar.gz"))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-18 14:32:45 +03:00
|
|
|
final def prepareLibevent = tasks.register("prepareLibevent", PrepareLibeventTask) {
|
|
|
|
it.dependsOn(dependenciesPath ? [] : [downloadLibevent])
|
|
|
|
it.libeventPath.setFrom(dependenciesPath ?: tarTree(downloadLibevent.dest))
|
|
|
|
it.libeventVersion.set(LIBEVENT_VERSION)
|
|
|
|
it.outputDir.set(new File(thirdPartyNdkDir, "libevent"))
|
2021-05-11 16:02:29 +03:00
|
|
|
}
|
|
|
|
|
2020-08-22 02:46:21 +03:00
|
|
|
task prepareHermes(dependsOn: createNativeDepsDirectories, type: Copy) {
|
2019-10-14 09:24:59 +03:00
|
|
|
def hermesPackagePath = findNodeModulePath(projectDir, "hermes-engine")
|
|
|
|
if (!hermesPackagePath) {
|
2020-05-20 00:15:19 +03:00
|
|
|
throw new GradleScriptException("Could not find the hermes-engine npm package", null)
|
2019-10-14 09:24:59 +03:00
|
|
|
}
|
2019-07-26 08:59:00 +03:00
|
|
|
|
2019-10-14 09:24:59 +03:00
|
|
|
def hermesAAR = file("$hermesPackagePath/android/hermes-debug.aar")
|
|
|
|
if (!hermesAAR.exists()) {
|
2020-05-20 00:15:19 +03:00
|
|
|
throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-debug.aar\"", null)
|
2019-07-26 08:59:00 +03:00
|
|
|
}
|
2019-10-14 09:24:59 +03:00
|
|
|
|
2019-07-26 08:59:00 +03:00
|
|
|
def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" })
|
|
|
|
|
2020-08-22 02:46:21 +03:00
|
|
|
from soFiles
|
|
|
|
from "src/main/jni/first-party/hermes/Android.mk"
|
|
|
|
into "$thirdPartyNdkDir/hermes"
|
2019-07-26 08:59:00 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 20:38:42 +03:00
|
|
|
task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {
|
2019-02-09 21:14:55 +03:00
|
|
|
src("https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz")
|
|
|
|
onlyIfNewer(true)
|
|
|
|
overwrite(false)
|
|
|
|
dest(new File(downloadsDir, "glog-${GLOG_VERSION}.tar.gz"))
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
2016-04-21 16:47:21 +03:00
|
|
|
// Prepare glog sources to be compiled, this task will perform steps that normally should've been
|
2015-09-16 20:38:42 +03:00
|
|
|
// executed by automake. This way we can avoid dependencies on make/automake
|
2021-10-18 14:32:45 +03:00
|
|
|
final def prepareGlog = tasks.register("prepareGlog", PrepareGlogTask) {
|
|
|
|
it.dependsOn(dependenciesPath ? [] : [downloadGlog])
|
|
|
|
it.glogPath.setFrom(dependenciesPath ?: tarTree(downloadGlog.dest))
|
|
|
|
it.glogVersion.set(GLOG_VERSION)
|
|
|
|
it.outputDir.set(new File(thirdPartyNdkDir, "glog"))
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
2018-12-28 01:45:36 +03:00
|
|
|
// Create Android.mk library module based on jsc from npm
|
2021-10-18 14:32:45 +03:00
|
|
|
tasks.register('prepareJSC', PrepareJSCTask) {
|
|
|
|
it.jscPackagePath.set(findNodeModulePath(projectDir, "jsc-android"))
|
|
|
|
it.outputDir = project.layout.buildDirectory.dir("third-party-ndk/jsc")
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
2021-10-18 14:32:45 +03:00
|
|
|
|
2018-03-30 06:59:47 +03:00
|
|
|
task downloadNdkBuildDependencies {
|
2018-12-28 01:45:36 +03:00
|
|
|
if (!boostPath) {
|
2019-02-09 21:14:55 +03:00
|
|
|
dependsOn(downloadBoost)
|
2018-12-28 01:45:36 +03:00
|
|
|
}
|
2019-02-09 21:14:55 +03:00
|
|
|
dependsOn(downloadDoubleConversion)
|
|
|
|
dependsOn(downloadFolly)
|
|
|
|
dependsOn(downloadGlog)
|
2021-05-11 16:02:29 +03:00
|
|
|
dependsOn(downloadFmt)
|
|
|
|
dependsOn(downloadLibevent)
|
2018-03-30 06:59:47 +03:00
|
|
|
}
|
|
|
|
|
2019-10-14 09:24:59 +03:00
|
|
|
/**
|
|
|
|
* Finds the path of the installed npm package with the given name using Node's
|
|
|
|
* module resolution algorithm, which searches "node_modules" directories up to
|
|
|
|
* the file system root. This handles various cases, including:
|
|
|
|
*
|
|
|
|
* - Working in the open-source RN repo:
|
|
|
|
* Gradle: /path/to/react-native/ReactAndroid
|
|
|
|
* Node module: /path/to/react-native/node_modules/[package]
|
|
|
|
*
|
|
|
|
* - Installing RN as a dependency of an app and searching for hoisted
|
|
|
|
* dependencies:
|
|
|
|
* Gradle: /path/to/app/node_modules/react-native/ReactAndroid
|
|
|
|
* Node module: /path/to/app/node_modules/[package]
|
|
|
|
*
|
|
|
|
* - Working in a larger repo (e.g., Facebook) that contains RN:
|
|
|
|
* Gradle: /path/to/repo/path/to/react-native/ReactAndroid
|
|
|
|
* Node module: /path/to/repo/node_modules/[package]
|
|
|
|
*
|
|
|
|
* The search begins at the given base directory (a File object). The returned
|
|
|
|
* path is a string.
|
|
|
|
*/
|
|
|
|
def findNodeModulePath(baseDir, packageName) {
|
|
|
|
def basePath = baseDir.toPath().normalize()
|
|
|
|
// Node's module resolution algorithm searches up to the root directory,
|
2020-07-31 03:06:54 +03:00
|
|
|
// after which the base path will be null
|
2019-10-14 09:24:59 +03:00
|
|
|
while (basePath) {
|
|
|
|
def candidatePath = Paths.get(basePath.toString(), "node_modules", packageName)
|
|
|
|
if (candidatePath.toFile().exists()) {
|
|
|
|
return candidatePath.toString()
|
|
|
|
}
|
|
|
|
basePath = basePath.getParent()
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2015-09-16 20:38:42 +03:00
|
|
|
|
2019-06-05 16:09:09 +03:00
|
|
|
def reactNativeDevServerPort() {
|
|
|
|
def value = project.getProperties().get("reactNativeDevServerPort")
|
|
|
|
return value != null ? value : "8081"
|
|
|
|
}
|
|
|
|
|
|
|
|
def reactNativeInspectorProxyPort() {
|
|
|
|
def value = project.getProperties().get("reactNativeInspectorProxyPort")
|
|
|
|
return value != null ? value : reactNativeDevServerPort()
|
|
|
|
}
|
|
|
|
|
2021-07-12 19:51:14 +03:00
|
|
|
def reactNativeArchitectures() {
|
2021-11-04 01:22:08 +03:00
|
|
|
def value = project.getProperties().get("reactNativeArchitectures")
|
|
|
|
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
2021-07-12 19:51:14 +03:00
|
|
|
}
|
|
|
|
|
2021-11-01 15:56:47 +03:00
|
|
|
def ndkBuildJobs() {
|
|
|
|
return project.findProperty("jobs") ?: Runtime.runtime.availableProcessors()
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
2021-11-08 15:24:54 +03:00
|
|
|
tasks.register("packageReactNdkLibsForBuck") {
|
|
|
|
dependsOn("packageReactNdkDebugLibsForBuck")
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register("packageReactNdkDebugLibsForBuck", Copy) {
|
2021-11-01 15:56:47 +03:00
|
|
|
dependsOn("mergeDebugNativeLibs")
|
2021-11-22 19:13:00 +03:00
|
|
|
// Shared libraries (.so) are copied from the merged_native_libs folder instead
|
2021-11-01 15:56:47 +03:00
|
|
|
from("$buildDir/intermediates/merged_native_libs/debug/out/lib/")
|
2019-04-05 00:12:44 +03:00
|
|
|
exclude("**/libjsc.so")
|
2019-07-26 08:59:00 +03:00
|
|
|
exclude("**/libhermes.so")
|
2019-02-09 21:14:55 +03:00
|
|
|
into("src/main/jni/prebuilt/lib")
|
2016-02-26 03:39:29 +03:00
|
|
|
}
|
|
|
|
|
2021-11-08 15:24:54 +03:00
|
|
|
tasks.register("packageReactNdkReleaseLibsForBuck", Copy) {
|
|
|
|
dependsOn("mergeReleaseNativeLibs")
|
2021-11-22 19:13:00 +03:00
|
|
|
// Shared libraries (.so) are copied from the merged_native_libs folder instead
|
2021-11-08 15:24:54 +03:00
|
|
|
from("$buildDir/intermediates/merged_native_libs/release/out/lib/")
|
|
|
|
exclude("**/libjsc.so")
|
|
|
|
exclude("**/libhermes.so")
|
|
|
|
into("src/main/jni/prebuilt/lib")
|
|
|
|
}
|
|
|
|
|
2021-10-18 14:32:45 +03:00
|
|
|
final def extractNativeDependencies = tasks.register('extractNativeDependencies', ExtractJniAndHeadersTask) {
|
|
|
|
it.extractHeadersConfiguration.setFrom(configurations.extractHeaders)
|
|
|
|
it.extractJniConfiguration.setFrom(configurations.extractJNI)
|
|
|
|
it.baseOutputDir = project.file("src/main/jni/first-party/")
|
|
|
|
// Sadly this task as an output folder path that is directly dependent on
|
|
|
|
// the task input (i.e. src/main/jni/first-party/<package-name>/...
|
|
|
|
// This means that this task is using the parent folder (first-party/) as
|
|
|
|
// @OutputFolder. The `prepareHermes` task will also output inside that
|
|
|
|
// folder and if the two tasks happen to be inside the same run, we want
|
|
|
|
// `extractNativeDependencies` to run after `prepareHermes` to do not
|
|
|
|
// invalidate the input/output calculation for this task.
|
|
|
|
it.mustRunAfter(prepareHermes)
|
2020-01-21 13:30:57 +03:00
|
|
|
}
|
|
|
|
|
2021-06-04 00:27:58 +03:00
|
|
|
task installArchives {
|
|
|
|
dependsOn("publishReleasePublicationToNpmRepository")
|
|
|
|
}
|
|
|
|
|
2015-09-16 20:38:42 +03:00
|
|
|
android {
|
2021-11-24 23:23:45 +03:00
|
|
|
compileSdkVersion 31
|
2022-01-11 20:59:23 +03:00
|
|
|
|
|
|
|
// Used to override the NDK path & version on internal CI
|
|
|
|
if (System.getenv("ANDROID_NDK") != null && System.getenv("LOCAL_ANDROID_NDK_VERSION") != null) {
|
|
|
|
ndkPath System.getenv("ANDROID_NDK")
|
|
|
|
ndkVersion System.getenv("LOCAL_ANDROID_NDK_VERSION")
|
2021-07-08 22:39:36 +03:00
|
|
|
}
|
2019-02-05 21:14:20 +03:00
|
|
|
|
2015-09-16 20:38:42 +03:00
|
|
|
defaultConfig {
|
2020-10-21 02:58:29 +03:00
|
|
|
minSdkVersion(21)
|
2021-11-24 23:23:45 +03:00
|
|
|
targetSdkVersion(31)
|
2019-02-09 21:14:55 +03:00
|
|
|
versionCode(1)
|
|
|
|
versionName("1.0")
|
2015-09-16 20:38:42 +03:00
|
|
|
|
2019-02-09 21:14:55 +03:00
|
|
|
consumerProguardFiles("proguard-rules.pro")
|
2018-04-06 03:26:39 +03:00
|
|
|
|
2019-02-09 21:14:55 +03:00
|
|
|
buildConfigField("boolean", "IS_INTERNAL_BUILD", "false")
|
|
|
|
buildConfigField("int", "EXOPACKAGE_FLAGS", "0")
|
2020-12-17 03:02:08 +03:00
|
|
|
buildConfigField("int", "HERMES_BYTECODE_VERSION", "0")
|
2019-06-05 16:09:09 +03:00
|
|
|
|
|
|
|
resValue "integer", "react_native_dev_server_port", reactNativeDevServerPort()
|
|
|
|
resValue "integer", "react_native_inspector_proxy_port", reactNativeInspectorProxyPort()
|
|
|
|
|
2019-02-09 21:14:55 +03:00
|
|
|
testApplicationId("com.facebook.react.tests.gradle")
|
2019-03-17 18:03:31 +03:00
|
|
|
testInstrumentationRunner("androidx.test.runner.AndroidJUnitRunner")
|
2021-11-01 15:56:47 +03:00
|
|
|
|
|
|
|
externalNativeBuild {
|
|
|
|
ndkBuild {
|
2021-11-04 01:22:08 +03:00
|
|
|
arguments "NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
|
2021-11-01 15:56:47 +03:00
|
|
|
"THIRD_PARTY_NDK_DIR=$thirdPartyNdkDir",
|
|
|
|
"REACT_COMMON_DIR=$projectDir/../ReactCommon",
|
|
|
|
"REACT_GENERATED_SRC_DIR=$buildDir/generated/source",
|
|
|
|
"REACT_SRC_DIR=$projectDir/src/main/java/com/facebook/react",
|
|
|
|
"-j${ndkBuildJobs()}"
|
|
|
|
|
|
|
|
if (Os.isFamily(Os.FAMILY_MAC)) {
|
|
|
|
// This flag will suppress "fcntl(): Bad file descriptor" warnings on local builds.
|
|
|
|
arguments "--output-sync=none"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-04 01:22:08 +03:00
|
|
|
ndk {
|
|
|
|
abiFilters (*reactNativeArchitectures())
|
|
|
|
}
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
2021-11-01 15:56:47 +03:00
|
|
|
externalNativeBuild {
|
|
|
|
ndkBuild {
|
|
|
|
path "src/main/jni/react/jni/Android.mk"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
preBuild.dependsOn(prepareJSC, prepareHermes, prepareBoost, prepareDoubleConversion, prepareFmt, prepareFolly, prepareGlog, prepareLibevent, extractNativeDependencies)
|
|
|
|
preBuild.dependsOn("generateCodegenArtifactsFromSchema")
|
|
|
|
|
2015-09-16 20:38:42 +03:00
|
|
|
sourceSets.main {
|
|
|
|
jni.srcDirs = []
|
2019-02-09 21:14:55 +03:00
|
|
|
res.srcDirs = ["src/main/res/devsupport", "src/main/res/shell", "src/main/res/views/modal", "src/main/res/views/uimanager"]
|
2016-01-07 14:51:28 +03:00
|
|
|
java {
|
2019-02-09 21:14:55 +03: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 14:51:28 +03:00
|
|
|
}
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
lintOptions {
|
2019-02-09 21:14:55 +03:00
|
|
|
abortOnError(false)
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
2020-01-21 13:30:57 +03:00
|
|
|
|
2016-06-16 14:04:34 +03:00
|
|
|
packagingOptions {
|
2019-02-09 21:14:55 +03:00
|
|
|
exclude("META-INF/NOTICE")
|
|
|
|
exclude("META-INF/LICENSE")
|
2016-06-16 14:04:34 +03:00
|
|
|
}
|
2020-01-21 13:30:57 +03:00
|
|
|
|
|
|
|
configurations {
|
|
|
|
extractHeaders
|
|
|
|
extractJNI
|
2020-11-18 05:26:00 +03:00
|
|
|
javadocDeps.extendsFrom api
|
2020-01-21 13:30:57 +03:00
|
|
|
}
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2021-07-14 01:07:18 +03:00
|
|
|
api("com.facebook.infer.annotation:infer-annotation:0.18.0")
|
2021-06-02 19:56:08 +03:00
|
|
|
api("com.facebook.yoga:proguard-annotations:1.19.0")
|
2019-02-09 21:14:55 +03:00
|
|
|
api("javax.inject:javax.inject:1")
|
2019-03-18 23:31:55 +03:00
|
|
|
api("androidx.appcompat:appcompat:1.0.2")
|
2021-07-22 01:13:34 +03:00
|
|
|
api("androidx.autofill:autofill:1.1.0")
|
PlatformColor implementations for iOS and Android (#27908)
Summary:
This Pull Request implements the PlatformColor proposal discussed at https://github.com/react-native-community/discussions-and-proposals/issues/126. The changes include implementations for iOS and Android as well as a PlatformColorExample page in RNTester.
Every native platform has the concept of system defined colors. Instead of specifying a concrete color value the app developer can choose a system color that varies in appearance depending on a system theme settings such Light or Dark mode, accessibility settings such as a High Contrast mode, and even its context within the app such as the traits of a containing view or window.
The proposal is to add true platform color support to react-native by extending the Flow type `ColorValue` with platform specific color type information for each platform and to provide a convenience function, `PlatformColor()`, for instantiating platform specific ColorValue objects.
`PlatformColor(name [, name ...])` where `name` is a system color name on a given platform. If `name` does not resolve to a color for any reason, the next `name` in the argument list will be resolved and so on. If none of the names resolve, a RedBox error occurs. This allows a latest platform color to be used, but if running on an older platform it will fallback to a previous version.
The function returns a `ColorValue`.
On iOS the values of `name` is one of the iOS [UI Element](https://developer.apple.com/documentation/uikit/uicolor/ui_element_colors) or [Standard Color](https://developer.apple.com/documentation/uikit/uicolor/standard_colors) names such as `labelColor` or `systemFillColor`.
On Android the `name` values are the same [app resource](https://developer.android.com/guide/topics/resources/providing-resources) path strings that can be expressed in XML:
XML Resource:
`@ [<package_name>:]<resource_type>/<resource_name>`
Style reference from current theme:
`?[<package_name>:][<resource_type>/]<resource_name>`
For example:
- `?android:colorError`
- `?android:attr/colorError`
- `?attr/colorPrimary`
- `?colorPrimaryDark`
- `android:color/holo_purple`
- `color/catalyst_redbox_background`
On iOS another type of system dynamic color can be created using the `IOSDynamicColor({dark: <color>, light:<color>})` method. The arguments are a tuple containing custom colors for light and dark themes. Such dynamic colors are useful for branding colors or other app specific colors that still respond automatically to system setting changes.
Example: `<View style={{ backgroundColor: IOSDynamicColor({light: 'black', dark: 'white'}) }}/>`
Other platforms could create platform specific functions similar to `IOSDynamicColor` per the needs of those platforms. For example, macOS has a similar dynamic color type that could be implemented via a `MacDynamicColor`. On Windows custom brushes that tint or otherwise modify a system brush could be created using a platform specific method.
## Changelog
[General] [Added] - Added PlatformColor implementations for iOS and Android
Pull Request resolved: https://github.com/facebook/react-native/pull/27908
Test Plan:
The changes have been tested using the RNTester test app for iOS and Android. On iOS a set of XCTestCase's were added to the Unit Tests.
<img width="924" alt="PlatformColor-ios-android" src="https://user-images.githubusercontent.com/30053638/73472497-ff183a80-433f-11ea-90d8-2b04338bbe79.png">
In addition `PlatformColor` support has been added to other out-of-tree platforms such as macOS and Windows has been implemented using these changes:
react-native for macOS branch: https://github.com/microsoft/react-native/compare/master...tom-un:tomun/platformcolors
react-native for Windows branch: https://github.com/microsoft/react-native-windows/compare/master...tom-un:tomun/platformcolors
iOS
|Light|Dark|
|{F229354502}|{F229354515}|
Android
|Light|Dark|
|{F230114392}|{F230114490}|
{F230122700}
Reviewed By: hramos
Differential Revision: D19837753
Pulled By: TheSavior
fbshipit-source-id: 82ca70d40802f3b24591bfd4b94b61f3c38ba829
2020-03-03 02:07:50 +03:00
|
|
|
api("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
|
2019-02-09 21:14:55 +03:00
|
|
|
api("com.facebook.fresco:fresco:${FRESCO_VERSION}")
|
|
|
|
api("com.facebook.fresco:imagepipeline-okhttp3:${FRESCO_VERSION}")
|
2021-01-15 02:45:51 +03:00
|
|
|
api("com.facebook.fresco:ui-common:${FRESCO_VERSION}")
|
2019-02-09 21:14:55 +03:00
|
|
|
api("com.facebook.soloader:soloader:${SO_LOADER_VERSION}")
|
|
|
|
api("com.google.code.findbugs:jsr305:3.0.2")
|
|
|
|
api("com.squareup.okhttp3:okhttp:${OKHTTP_VERSION}")
|
|
|
|
api("com.squareup.okhttp3:okhttp-urlconnection:${OKHTTP_VERSION}")
|
2021-04-08 20:44:10 +03:00
|
|
|
api("com.squareup.okio:okio:2.9.0")
|
2021-03-25 21:26:46 +03:00
|
|
|
api("com.facebook.fbjni:fbjni-java-only:0.2.2")
|
|
|
|
extractHeaders("com.facebook.fbjni:fbjni:0.2.2:headers")
|
|
|
|
extractJNI("com.facebook.fbjni:fbjni:0.2.2")
|
2019-02-09 21:14:55 +03:00
|
|
|
|
2020-11-18 05:26:00 +03:00
|
|
|
javadocDeps("com.squareup:javapoet:1.13.0")
|
|
|
|
|
2019-02-09 21:14:55 +03:00
|
|
|
testImplementation("junit:junit:${JUNIT_VERSION}")
|
2020-05-27 06:36:38 +03:00
|
|
|
testImplementation("org.powermock:powermock-api-mockito2:${POWERMOCK_VERSION}")
|
2019-02-09 21:14:55 +03:00
|
|
|
testImplementation("org.powermock:powermock-module-junit4-rule:${POWERMOCK_VERSION}")
|
|
|
|
testImplementation("org.powermock:powermock-classloading-xstream:${POWERMOCK_VERSION}")
|
|
|
|
testImplementation("org.mockito:mockito-core:${MOCKITO_CORE_VERSION}")
|
2021-12-16 21:39:20 +03:00
|
|
|
testImplementation("org.assertj:assertj-core:3.21.0")
|
2019-02-09 21:14:55 +03:00
|
|
|
testImplementation("org.robolectric:robolectric:${ROBOLECTRIC_VERSION}")
|
|
|
|
|
|
|
|
androidTestImplementation(fileTree(dir: "src/main/third-party/java/buck-android-support/", include: ["*.jar"]))
|
2019-09-20 01:32:47 +03:00
|
|
|
androidTestImplementation("androidx.test:runner:${ANDROIDX_TEST_VERSION}")
|
|
|
|
androidTestImplementation("androidx.test:rules:${ANDROIDX_TEST_VERSION}")
|
2019-02-09 21:14:55 +03:00
|
|
|
androidTestImplementation("org.mockito:mockito-core:${MOCKITO_CORE_VERSION}")
|
2015-09-16 20:38:42 +03:00
|
|
|
}
|
|
|
|
|
2021-09-16 15:36:25 +03:00
|
|
|
react {
|
2020-12-22 09:41:06 +03:00
|
|
|
// TODO: The library name is chosen for parity with Fabric components & iOS
|
|
|
|
// This should be changed to a more generic name, e.g. `ReactCoreSpec`.
|
|
|
|
libraryName = "rncore"
|
2020-08-12 21:10:33 +03:00
|
|
|
jsRootDir = file("../Libraries")
|
2021-09-15 19:21:12 +03:00
|
|
|
reactRoot = file("$projectDir/..")
|
2021-10-20 16:07:16 +03:00
|
|
|
useJavaGenerator = System.getenv("USE_CODEGEN_JAVAPOET")?.toBoolean() ?: false
|
2021-10-20 19:32:14 +03:00
|
|
|
// We search for the codegen in either one of the `node_modules` folder or in the
|
|
|
|
// root packages folder (that's for when we build from source without calling `yarn install`).
|
|
|
|
codegenDir = file(findNodeModulePath(projectDir, "react-native-codegen") ?: "../packages/react-native-codegen/")
|
2020-08-12 21:10:33 +03:00
|
|
|
}
|
2021-06-04 00:27:58 +03:00
|
|
|
|
|
|
|
afterEvaluate {
|
2021-11-24 21:57:09 +03:00
|
|
|
|
|
|
|
// Needed as some of the native sources needs to be downloaded
|
|
|
|
// before configureNdkBuildDebug could be executed.
|
|
|
|
configureNdkBuildDebug.dependsOn(preBuild)
|
|
|
|
configureNdkBuildRelease.dependsOn(preBuild)
|
|
|
|
|
2021-06-04 00:27:58 +03:00
|
|
|
publishing {
|
|
|
|
publications {
|
|
|
|
release(MavenPublication) {
|
|
|
|
// Applies the component for the release build variant.
|
|
|
|
from components.release
|
|
|
|
|
|
|
|
// You can then customize attributes of the publication as shown below.
|
|
|
|
artifactId = POM_ARTIFACT_ID
|
|
|
|
groupId = GROUP
|
|
|
|
version = VERSION_NAME
|
|
|
|
|
|
|
|
pom {
|
|
|
|
name = POM_NAME
|
|
|
|
description = "A framework for building native apps with React"
|
|
|
|
url = "https://github.com/facebook/react-native"
|
|
|
|
|
|
|
|
developers {
|
|
|
|
developer {
|
|
|
|
id = "facebook"
|
|
|
|
name = "Facebook"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
licenses {
|
|
|
|
license {
|
|
|
|
name = "MIT License"
|
2021-07-15 22:22:38 +03:00
|
|
|
url = "https://github.com/facebook/react-native/blob/HEAD/LICENSE"
|
2021-06-04 00:27:58 +03:00
|
|
|
distribution = "repo"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scm {
|
|
|
|
url = "https://github.com/facebook/react-native.git"
|
|
|
|
connection = "scm:git:https://github.com/facebook/react-native.git"
|
|
|
|
developerConnection = "scm:git:git@github.com:facebook/react-native.git"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
repositories {
|
|
|
|
maven {
|
|
|
|
name = "npm"
|
|
|
|
url = AAR_OUTPUT_URL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|