@react-native/gradle-plugin 0.73.0 → 0.73.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/build.gradle.kts +20 -13
- package/gradle/libs.versions.toml +18 -0
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +3 -1
- package/gradlew +17 -8
- package/gradlew.bat +1 -0
- package/package.json +14 -5
- package/settings.gradle.kts +2 -0
- package/src/main/kotlin/com/facebook/react/ReactPlugin.kt +18 -24
- package/src/main/kotlin/com/facebook/react/TaskConfiguration.kt +1 -1
- package/src/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt +3 -2
- package/src/main/kotlin/com/facebook/react/model/ModelPackageJson.kt +1 -1
- package/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt +1 -0
- package/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt +1 -1
- package/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt +2 -7
- package/src/main/kotlin/com/facebook/react/tasks/{BuildCodegenCLITask.kt → internal/BuildCodegenCLITask.kt} +10 -17
- package/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +6 -2
- package/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +67 -21
- package/src/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt +52 -0
- package/src/main/kotlin/com/facebook/react/utils/JsonUtils.kt +1 -1
- package/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt +16 -8
- package/src/main/kotlin/com/facebook/react/utils/PathUtils.kt +3 -3
- package/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +65 -10
- package/src/main/kotlin/com/facebook/react/utils/PropertyUtils.kt +55 -0
package/README.md
CHANGED
|
@@ -14,3 +14,10 @@ yarn add @react-native/gradle-plugin
|
|
|
14
14
|
|
|
15
15
|
[version-badge]: https://img.shields.io/npm/v/@react-native/gradle-plugin?style=flat-square
|
|
16
16
|
[package]: https://www.npmjs.com/package/@react-native/gradle-plugin
|
|
17
|
+
|
|
18
|
+
## Testing
|
|
19
|
+
|
|
20
|
+
To run the tests in this package, run the following commands from the React Native root folder:
|
|
21
|
+
|
|
22
|
+
1. `yarn` to install the dependencies. You just need to run this once
|
|
23
|
+
2. `yarn jest packages/react-native-gradle-plugin`.
|
package/build.gradle.kts
CHANGED
|
@@ -11,7 +11,7 @@ import org.gradle.configurationcache.extensions.serviceOf
|
|
|
11
11
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
12
12
|
|
|
13
13
|
plugins {
|
|
14
|
-
kotlin
|
|
14
|
+
alias(libs.plugins.kotlin.jvm)
|
|
15
15
|
id("java-gradle-plugin")
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -33,12 +33,17 @@ group = "com.facebook.react"
|
|
|
33
33
|
|
|
34
34
|
dependencies {
|
|
35
35
|
implementation(gradleApi())
|
|
36
|
-
implementation("com.android.tools.build:gradle:7.4.2")
|
|
37
|
-
implementation("com.google.code.gson:gson:2.8.9")
|
|
38
|
-
implementation("com.google.guava:guava:31.0.1-jre")
|
|
39
|
-
implementation("com.squareup:javapoet:1.13.0")
|
|
40
36
|
|
|
41
|
-
|
|
37
|
+
// The KGP/AGP version is defined by React Native Gradle plugin.
|
|
38
|
+
// Therefore we specify an implementation dep rather than a compileOnly.
|
|
39
|
+
implementation(libs.kotlin.gradle.plugin)
|
|
40
|
+
implementation(libs.android.gradle.plugin)
|
|
41
|
+
|
|
42
|
+
implementation(libs.gson)
|
|
43
|
+
implementation(libs.guava)
|
|
44
|
+
implementation(libs.javapoet)
|
|
45
|
+
|
|
46
|
+
testImplementation(libs.junit)
|
|
42
47
|
|
|
43
48
|
testRuntimeOnly(
|
|
44
49
|
files(
|
|
@@ -49,16 +54,18 @@ dependencies {
|
|
|
49
54
|
.first()))
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
57
|
+
// We intentionally don't build for Java 17 as users will see a cryptic bytecode version
|
|
58
|
+
// error first. Instead we produce a Java 11-compatible Gradle Plugin, so that AGP can print their
|
|
59
|
+
// nice message showing that JDK 11 (or 17) is required first
|
|
60
|
+
java { targetCompatibility = JavaVersion.VERSION_11 }
|
|
61
|
+
|
|
62
|
+
kotlin { jvmToolchain(17) }
|
|
56
63
|
|
|
57
|
-
tasks.withType<KotlinCompile> {
|
|
64
|
+
tasks.withType<KotlinCompile>().configureEach {
|
|
58
65
|
kotlinOptions {
|
|
59
|
-
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
60
66
|
apiVersion = "1.5"
|
|
61
|
-
|
|
67
|
+
// See comment above on JDK 11 support
|
|
68
|
+
jvmTarget = "11"
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
71
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[versions]
|
|
2
|
+
agp = "8.1.1"
|
|
3
|
+
gson = "2.8.9"
|
|
4
|
+
guava = "31.0.1-jre"
|
|
5
|
+
javapoet = "1.13.0"
|
|
6
|
+
junit = "4.13.2"
|
|
7
|
+
kotlin = "1.8.0"
|
|
8
|
+
|
|
9
|
+
[libraries]
|
|
10
|
+
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
|
11
|
+
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agp" }
|
|
12
|
+
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
|
|
13
|
+
guava = { module = "com.google.guava:guava", version.ref = "guava" }
|
|
14
|
+
javapoet = { module = "com.squareup:javapoet", version.ref = "javapoet" }
|
|
15
|
+
junit = {module = "junit:junit", version.ref = "junit" }
|
|
16
|
+
|
|
17
|
+
[plugins]
|
|
18
|
+
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
|
Binary file
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
distributionBase=GRADLE_USER_HOME
|
|
2
2
|
distributionPath=wrapper/dists
|
|
3
|
-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.
|
|
3
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
|
|
4
|
+
networkTimeout=10000
|
|
5
|
+
validateDistributionUrl=true
|
|
4
6
|
zipStoreBase=GRADLE_USER_HOME
|
|
5
7
|
zipStorePath=wrapper/dists
|
package/gradlew
CHANGED
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
# Darwin, MinGW, and NonStop.
|
|
56
56
|
#
|
|
57
57
|
# (3) This script is generated from the Groovy template
|
|
58
|
-
# https://github.com/gradle/gradle/blob/
|
|
58
|
+
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
|
59
59
|
# within the Gradle project.
|
|
60
60
|
#
|
|
61
61
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
|
@@ -80,13 +80,11 @@ do
|
|
|
80
80
|
esac
|
|
81
81
|
done
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
APP_NAME="Gradle"
|
|
83
|
+
# This is normally unused
|
|
84
|
+
# shellcheck disable=SC2034
|
|
86
85
|
APP_BASE_NAME=${0##*/}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
86
|
+
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
|
87
|
+
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
|
90
88
|
|
|
91
89
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
92
90
|
MAX_FD=maximum
|
|
@@ -133,22 +131,29 @@ location of your Java installation."
|
|
|
133
131
|
fi
|
|
134
132
|
else
|
|
135
133
|
JAVACMD=java
|
|
136
|
-
|
|
134
|
+
if ! command -v java >/dev/null 2>&1
|
|
135
|
+
then
|
|
136
|
+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
137
137
|
|
|
138
138
|
Please set the JAVA_HOME variable in your environment to match the
|
|
139
139
|
location of your Java installation."
|
|
140
|
+
fi
|
|
140
141
|
fi
|
|
141
142
|
|
|
142
143
|
# Increase the maximum file descriptors if we can.
|
|
143
144
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|
144
145
|
case $MAX_FD in #(
|
|
145
146
|
max*)
|
|
147
|
+
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
|
148
|
+
# shellcheck disable=SC3045
|
|
146
149
|
MAX_FD=$( ulimit -H -n ) ||
|
|
147
150
|
warn "Could not query maximum file descriptor limit"
|
|
148
151
|
esac
|
|
149
152
|
case $MAX_FD in #(
|
|
150
153
|
'' | soft) :;; #(
|
|
151
154
|
*)
|
|
155
|
+
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
|
156
|
+
# shellcheck disable=SC3045
|
|
152
157
|
ulimit -n "$MAX_FD" ||
|
|
153
158
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
|
154
159
|
esac
|
|
@@ -193,6 +198,10 @@ if "$cygwin" || "$msys" ; then
|
|
|
193
198
|
done
|
|
194
199
|
fi
|
|
195
200
|
|
|
201
|
+
|
|
202
|
+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
203
|
+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
204
|
+
|
|
196
205
|
# Collect all arguments for the java command;
|
|
197
206
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
|
198
207
|
# shell script including quotes and variable substitutions, so put them in
|
package/gradlew.bat
CHANGED
package/package.json
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/gradle-plugin",
|
|
3
|
-
"version": "0.73.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "0.73.1",
|
|
4
|
+
"description": "Gradle Plugin for React Native",
|
|
5
|
+
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "
|
|
8
|
+
"url": "https://github.com/facebook/react-native.git",
|
|
9
9
|
"directory": "packages/react-native-gradle-plugin"
|
|
10
10
|
},
|
|
11
|
+
"homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/react-native-gradle-plugin#readme",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"gradle",
|
|
14
|
+
"plugin",
|
|
15
|
+
"react-native"
|
|
16
|
+
],
|
|
17
|
+
"bugs": "https://github.com/facebook/react-native/issues",
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18"
|
|
20
|
+
},
|
|
11
21
|
"scripts": {
|
|
12
22
|
"build": "./gradlew build",
|
|
13
23
|
"clean": "./gradlew clean",
|
|
14
24
|
"test": "./gradlew check"
|
|
15
25
|
},
|
|
16
|
-
"license": "MIT",
|
|
17
26
|
"files": [
|
|
18
27
|
"settings.gradle.kts",
|
|
19
28
|
"build.gradle.kts",
|
package/settings.gradle.kts
CHANGED
|
@@ -10,7 +10,6 @@ package com.facebook.react
|
|
|
10
10
|
import com.android.build.api.variant.AndroidComponentsExtension
|
|
11
11
|
import com.android.build.gradle.internal.tasks.factory.dependsOn
|
|
12
12
|
import com.facebook.react.internal.PrivateReactExtension
|
|
13
|
-
import com.facebook.react.tasks.BuildCodegenCLITask
|
|
14
13
|
import com.facebook.react.tasks.GenerateCodegenArtifactsTask
|
|
15
14
|
import com.facebook.react.tasks.GenerateCodegenSchemaTask
|
|
16
15
|
import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFields
|
|
@@ -18,7 +17,8 @@ import com.facebook.react.utils.AgpConfiguratorUtils.configureDevPorts
|
|
|
18
17
|
import com.facebook.react.utils.BackwardCompatUtils.configureBackwardCompatibilityReactMap
|
|
19
18
|
import com.facebook.react.utils.DependencyUtils.configureDependencies
|
|
20
19
|
import com.facebook.react.utils.DependencyUtils.configureRepositories
|
|
21
|
-
import com.facebook.react.utils.DependencyUtils.
|
|
20
|
+
import com.facebook.react.utils.DependencyUtils.readVersionAndGroupStrings
|
|
21
|
+
import com.facebook.react.utils.JdkConfiguratorUtils.configureJavaToolChains
|
|
22
22
|
import com.facebook.react.utils.JsonUtils
|
|
23
23
|
import com.facebook.react.utils.NdkConfiguratorUtils.configureReactNativeNdk
|
|
24
24
|
import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
|
|
@@ -28,6 +28,8 @@ import kotlin.system.exitProcess
|
|
|
28
28
|
import org.gradle.api.Plugin
|
|
29
29
|
import org.gradle.api.Project
|
|
30
30
|
import org.gradle.api.Task
|
|
31
|
+
import org.gradle.api.file.Directory
|
|
32
|
+
import org.gradle.api.provider.Provider
|
|
31
33
|
import org.gradle.internal.jvm.Jvm
|
|
32
34
|
|
|
33
35
|
class ReactPlugin : Plugin<Project> {
|
|
@@ -54,13 +56,15 @@ class ReactPlugin : Plugin<Project> {
|
|
|
54
56
|
project.afterEvaluate {
|
|
55
57
|
val reactNativeDir = extension.reactNativeDir.get().asFile
|
|
56
58
|
val propertiesFile = File(reactNativeDir, "ReactAndroid/gradle.properties")
|
|
57
|
-
val
|
|
58
|
-
|
|
59
|
+
val versionAndGroupStrings = readVersionAndGroupStrings(propertiesFile)
|
|
60
|
+
val versionString = versionAndGroupStrings.first
|
|
61
|
+
val groupString = versionAndGroupStrings.second
|
|
62
|
+
configureDependencies(project, versionString, groupString)
|
|
59
63
|
configureRepositories(project, reactNativeDir)
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
configureReactNativeNdk(project, extension)
|
|
63
|
-
configureBuildConfigFields(project)
|
|
67
|
+
configureBuildConfigFields(project, extension)
|
|
64
68
|
configureDevPorts(project)
|
|
65
69
|
configureBackwardCompatibilityReactMap(project)
|
|
66
70
|
|
|
@@ -76,17 +80,20 @@ class ReactPlugin : Plugin<Project> {
|
|
|
76
80
|
project.pluginManager.withPlugin("com.android.library") {
|
|
77
81
|
configureCodegen(project, extension, rootExtension, isLibrary = true)
|
|
78
82
|
}
|
|
83
|
+
|
|
84
|
+
// Library and App Configurations
|
|
85
|
+
configureJavaToolChains(project)
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
private fun checkJvmVersion(project: Project) {
|
|
82
89
|
val jvmVersion = Jvm.current()?.javaVersion?.majorVersion
|
|
83
|
-
if ((jvmVersion?.toIntOrNull() ?: 0) <=
|
|
90
|
+
if ((jvmVersion?.toIntOrNull() ?: 0) <= 16) {
|
|
84
91
|
project.logger.error(
|
|
85
92
|
"""
|
|
86
93
|
|
|
87
94
|
********************************************************************************
|
|
88
95
|
|
|
89
|
-
ERROR: requires
|
|
96
|
+
ERROR: requires JDK17 or higher.
|
|
90
97
|
Incompatible major version detected: '$jvmVersion'
|
|
91
98
|
|
|
92
99
|
********************************************************************************
|
|
@@ -106,7 +113,8 @@ class ReactPlugin : Plugin<Project> {
|
|
|
106
113
|
isLibrary: Boolean
|
|
107
114
|
) {
|
|
108
115
|
// First, we set up the output dir for the codegen.
|
|
109
|
-
val generatedSrcDir =
|
|
116
|
+
val generatedSrcDir: Provider<Directory> =
|
|
117
|
+
project.layout.buildDirectory.dir("generated/source/codegen")
|
|
110
118
|
|
|
111
119
|
// We specify the default value (convention) for jsRootDir.
|
|
112
120
|
// It's the root folder for apps (so ../../ from the Gradle project)
|
|
@@ -117,24 +125,10 @@ class ReactPlugin : Plugin<Project> {
|
|
|
117
125
|
localExtension.jsRootDir.convention(localExtension.root)
|
|
118
126
|
}
|
|
119
127
|
|
|
120
|
-
val buildCodegenTask =
|
|
121
|
-
project.tasks.register("buildCodegenCLI", BuildCodegenCLITask::class.java) {
|
|
122
|
-
it.codegenDir.set(rootExtension.codegenDir)
|
|
123
|
-
val bashWindowsHome = project.findProperty("REACT_WINDOWS_BASH") as String?
|
|
124
|
-
it.bashWindowsHome.set(bashWindowsHome)
|
|
125
|
-
|
|
126
|
-
// Please note that appNeedsCodegen is triggering a read of the package.json at
|
|
127
|
-
// configuration time as we need to feed the onlyIf condition of this task.
|
|
128
|
-
// Therefore, the appNeedsCodegen needs to be invoked inside this lambda.
|
|
129
|
-
val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(rootExtension.root)
|
|
130
|
-
it.onlyIf { isLibrary || needsCodegenFromPackageJson }
|
|
131
|
-
}
|
|
132
|
-
|
|
133
128
|
// We create the task to produce schema from JS files.
|
|
134
129
|
val generateCodegenSchemaTask =
|
|
135
130
|
project.tasks.register(
|
|
136
131
|
"generateCodegenSchemaFromJavaScript", GenerateCodegenSchemaTask::class.java) { it ->
|
|
137
|
-
it.dependsOn(buildCodegenTask)
|
|
138
132
|
it.nodeExecutableAndArgs.set(rootExtension.nodeExecutableAndArgs)
|
|
139
133
|
it.codegenDir.set(rootExtension.codegenDir)
|
|
140
134
|
it.generatedSrcDir.set(generatedSrcDir)
|
|
@@ -143,7 +137,7 @@ class ReactPlugin : Plugin<Project> {
|
|
|
143
137
|
// the `jsRootDir` @Input property of this task & the onlyIf. Therefore, the
|
|
144
138
|
// parsePackageJson should be invoked inside this lambda.
|
|
145
139
|
val packageJson = findPackageJsonFile(project, rootExtension.root)
|
|
146
|
-
val parsedPackageJson = packageJson?.let { JsonUtils.
|
|
140
|
+
val parsedPackageJson = packageJson?.let { JsonUtils.fromPackageJson(it) }
|
|
147
141
|
|
|
148
142
|
val jsSrcsDirInPackageJson = parsedPackageJson?.codegenConfig?.jsSrcsDir
|
|
149
143
|
if (jsSrcsDirInPackageJson != null) {
|
|
@@ -181,7 +175,7 @@ class ReactPlugin : Plugin<Project> {
|
|
|
181
175
|
//
|
|
182
176
|
// android { sourceSets { main { java { srcDirs += "$generatedSrcDir/java" } } } }
|
|
183
177
|
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
|
|
184
|
-
ext.sourceSets.getByName("main").java.srcDir(
|
|
178
|
+
ext.sourceSets.getByName("main").java.srcDir(generatedSrcDir.get().dir("java").asFile)
|
|
185
179
|
}
|
|
186
180
|
|
|
187
181
|
// `preBuild` is one of the base tasks automatically registered by AGP.
|
|
@@ -48,7 +48,7 @@ internal fun Project.configureReactTasks(variant: Variant, config: ReactExtensio
|
|
|
48
48
|
val isDebuggableVariant =
|
|
49
49
|
config.debuggableVariants.get().any { it.equals(variant.name, ignoreCase = true) }
|
|
50
50
|
|
|
51
|
-
configureNewArchPackagingOptions(project, variant)
|
|
51
|
+
configureNewArchPackagingOptions(project, config, variant)
|
|
52
52
|
configureJsEnginePackagingOptions(config, variant, isHermesEnabledInThisVariant)
|
|
53
53
|
|
|
54
54
|
if (!isDebuggableVariant) {
|
|
@@ -30,7 +30,7 @@ abstract class PrivateReactExtension @Inject constructor(project: Project) {
|
|
|
30
30
|
.directoryProperty()
|
|
31
31
|
.convention(
|
|
32
32
|
// This is the default for the project root if the users hasn't specified anything.
|
|
33
|
-
// If the project is called "react-native-github"
|
|
33
|
+
// If the project is called "react-native-github" or "react-native-build-from-source"
|
|
34
34
|
// - We're inside the Github Repo -> root is defined by RN Tester (so no default
|
|
35
35
|
// needed)
|
|
36
36
|
// - We're inside an includedBuild as we're performing a build from source
|
|
@@ -39,7 +39,8 @@ abstract class PrivateReactExtension @Inject constructor(project: Project) {
|
|
|
39
39
|
// - We're inside a user project, so inside the ./android folder. Default should be
|
|
40
40
|
// ../
|
|
41
41
|
// User can always override this default by setting a `root =` inside the template.
|
|
42
|
-
if (project.rootProject.name == "react-native-github"
|
|
42
|
+
if (project.rootProject.name == "react-native-github" ||
|
|
43
|
+
project.rootProject.name == "react-native-build-from-source") {
|
|
43
44
|
project.rootProject.layout.projectDirectory.dir("../../")
|
|
44
45
|
} else {
|
|
45
46
|
project.rootProject.layout.projectDirectory.dir("../")
|
|
@@ -53,7 +53,7 @@ abstract class GenerateCodegenArtifactsTask : Exec() {
|
|
|
53
53
|
internal fun resolveTaskParameters(): Pair<String, String> {
|
|
54
54
|
val parsedPackageJson =
|
|
55
55
|
if (packageJsonFile.isPresent && packageJsonFile.get().asFile.exists()) {
|
|
56
|
-
JsonUtils.
|
|
56
|
+
JsonUtils.fromPackageJson(packageJsonFile.get().asFile)
|
|
57
57
|
} else {
|
|
58
58
|
null
|
|
59
59
|
}
|
|
@@ -35,13 +35,8 @@ abstract class GenerateCodegenSchemaTask : Exec() {
|
|
|
35
35
|
project.fileTree(jsRootDir) {
|
|
36
36
|
it.include("**/*.js")
|
|
37
37
|
it.include("**/*.ts")
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
// for execution avoidance.
|
|
41
|
-
it.exclude("**/build/ASSETS/**/*")
|
|
42
|
-
it.exclude("**/build/RES/**/*")
|
|
43
|
-
it.exclude("**/build/generated/**/*")
|
|
44
|
-
it.exclude("**/build/intermediates/**/*")
|
|
38
|
+
// We want to exclude the build directory, to don't pick them up for execution avoidance.
|
|
39
|
+
it.exclude("**/build/**/*")
|
|
45
40
|
}
|
|
46
41
|
|
|
47
42
|
@get:OutputFile
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
package com.facebook.react.tasks
|
|
8
|
+
package com.facebook.react.tasks.internal
|
|
9
9
|
|
|
10
10
|
import com.facebook.react.utils.Os.unixifyPath
|
|
11
11
|
import com.facebook.react.utils.windowsAwareBashCommandLine
|
|
12
12
|
import org.gradle.api.file.DirectoryProperty
|
|
13
|
-
import org.gradle.api.file.
|
|
13
|
+
import org.gradle.api.file.FileTree
|
|
14
14
|
import org.gradle.api.provider.Property
|
|
15
15
|
import org.gradle.api.tasks.*
|
|
16
16
|
|
|
@@ -27,21 +27,14 @@ abstract class BuildCodegenCLITask : Exec() {
|
|
|
27
27
|
@get:Internal abstract val bashWindowsHome: Property<String>
|
|
28
28
|
|
|
29
29
|
@get:InputFiles
|
|
30
|
-
val
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// We need this condition as we want a single instance of BuildCodegenCLITask to execute
|
|
39
|
-
// per project. Therefore we can safely skip the task if the lib/cli/ folder is available.
|
|
40
|
-
onlyIf {
|
|
41
|
-
val cliDir = codegenDir.file("lib/cli/").get().asFile
|
|
42
|
-
!cliDir.exists() || cliDir.listFiles()?.size == 0
|
|
43
|
-
}
|
|
44
|
-
}
|
|
30
|
+
val inputFiles: FileTree = project.fileTree(codegenDir) { it.include("src/**/*.js") }
|
|
31
|
+
|
|
32
|
+
@get:OutputFiles
|
|
33
|
+
val outputFiles: FileTree =
|
|
34
|
+
project.fileTree(codegenDir) {
|
|
35
|
+
it.include("lib/**/*.js")
|
|
36
|
+
it.include("lib/**/*.js.flow")
|
|
37
|
+
}
|
|
45
38
|
|
|
46
39
|
override fun exec() {
|
|
47
40
|
commandLine(
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
package com.facebook.react.utils
|
|
9
9
|
|
|
10
10
|
import com.android.build.api.variant.AndroidComponentsExtension
|
|
11
|
+
import com.facebook.react.ReactExtension
|
|
11
12
|
import com.facebook.react.utils.ProjectUtils.isHermesEnabled
|
|
12
13
|
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
|
|
13
14
|
import org.gradle.api.Action
|
|
@@ -17,12 +18,15 @@ import org.gradle.api.plugins.AppliedPlugin
|
|
|
17
18
|
@Suppress("UnstableApiUsage")
|
|
18
19
|
internal object AgpConfiguratorUtils {
|
|
19
20
|
|
|
20
|
-
fun configureBuildConfigFields(project: Project) {
|
|
21
|
+
fun configureBuildConfigFields(project: Project, extension: ReactExtension) {
|
|
21
22
|
val action =
|
|
22
23
|
Action<AppliedPlugin> {
|
|
23
24
|
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
|
|
25
|
+
ext.buildFeatures.buildConfig = true
|
|
24
26
|
ext.defaultConfig.buildConfigField(
|
|
25
|
-
"boolean",
|
|
27
|
+
"boolean",
|
|
28
|
+
"IS_NEW_ARCHITECTURE_ENABLED",
|
|
29
|
+
project.isNewArchEnabled(extension).toString())
|
|
26
30
|
ext.defaultConfig.buildConfigField(
|
|
27
31
|
"boolean", "IS_HERMES_ENABLED", project.isHermesEnabled.toString())
|
|
28
32
|
}
|
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
package com.facebook.react.utils
|
|
9
9
|
|
|
10
|
+
import com.facebook.react.utils.PropertyUtils.DEFAULT_INTERNAL_PUBLISHING_GROUP
|
|
11
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_PUBLISHING_GROUP
|
|
12
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO
|
|
13
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_USE_HERMES_NIGHTLY
|
|
14
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_VERSION_NAME
|
|
10
15
|
import java.io.File
|
|
11
16
|
import java.net.URI
|
|
12
17
|
import java.util.*
|
|
@@ -22,8 +27,8 @@ internal object DependencyUtils {
|
|
|
22
27
|
fun configureRepositories(project: Project, reactNativeDir: File) {
|
|
23
28
|
project.rootProject.allprojects { eachProject ->
|
|
24
29
|
with(eachProject) {
|
|
25
|
-
if (hasProperty(
|
|
26
|
-
val mavenLocalRepoPath = property(
|
|
30
|
+
if (hasProperty(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO)) {
|
|
31
|
+
val mavenLocalRepoPath = property(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO) as String
|
|
27
32
|
mavenRepoFromURI(File(mavenLocalRepoPath).toURI())
|
|
28
33
|
}
|
|
29
34
|
// We add the snapshot for users on nightlies.
|
|
@@ -43,10 +48,15 @@ internal object DependencyUtils {
|
|
|
43
48
|
/**
|
|
44
49
|
* This method takes care of configuring the resolution strategy for both the app and all the 3rd
|
|
45
50
|
* party libraries which are auto-linked. Specifically it takes care of:
|
|
46
|
-
* - Forcing the react-android/hermes-android version to the one specified in
|
|
51
|
+
* - Forcing the react-android/hermes-android/flipper-integration version to the one specified in
|
|
52
|
+
* the package.json
|
|
47
53
|
* - Substituting `react-native` with `react-android` and `hermes-engine` with `hermes-android`.
|
|
48
54
|
*/
|
|
49
|
-
fun configureDependencies(
|
|
55
|
+
fun configureDependencies(
|
|
56
|
+
project: Project,
|
|
57
|
+
versionString: String,
|
|
58
|
+
groupString: String = DEFAULT_INTERNAL_PUBLISHING_GROUP
|
|
59
|
+
) {
|
|
50
60
|
if (versionString.isBlank()) return
|
|
51
61
|
project.rootProject.allprojects { eachProject ->
|
|
52
62
|
eachProject.configurations.all { configuration ->
|
|
@@ -55,33 +65,69 @@ internal object DependencyUtils {
|
|
|
55
65
|
// This allows users to import libraries that are still using
|
|
56
66
|
// implementation("com.facebook.react:react-native:+") and resolve the right dependency.
|
|
57
67
|
configuration.resolutionStrategy.dependencySubstitution {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"The react-native artifact was deprecated in favor of react-android due to https://github.com/facebook/react-native/issues/35210.")
|
|
62
|
-
it.substitute(it.module("com.facebook.react:hermes-engine"))
|
|
63
|
-
.using(it.module("com.facebook.react:hermes-android:${versionString}"))
|
|
64
|
-
.because(
|
|
65
|
-
"The hermes-engine artifact was deprecated in favor of hermes-android due to https://github.com/facebook/react-native/issues/35210.")
|
|
68
|
+
getDependencySubstitutions(versionString, groupString).forEach { (module, dest, reason) ->
|
|
69
|
+
it.substitute(it.module(module)).using(it.module(dest)).because(reason)
|
|
70
|
+
}
|
|
66
71
|
}
|
|
67
72
|
configuration.resolutionStrategy.force(
|
|
68
|
-
"
|
|
69
|
-
"
|
|
73
|
+
"${groupString}:react-android:${versionString}",
|
|
74
|
+
"${groupString}:flipper-integration:${versionString}",
|
|
70
75
|
)
|
|
76
|
+
if (!(eachProject.findProperty(INTERNAL_USE_HERMES_NIGHTLY) as? String).toBoolean()) {
|
|
77
|
+
// Contributors only: The hermes-engine version is forced only if the user has
|
|
78
|
+
// not opted into using nightlies for local development.
|
|
79
|
+
configuration.resolutionStrategy.force("${groupString}:hermes-android:${versionString}")
|
|
80
|
+
}
|
|
71
81
|
}
|
|
72
82
|
}
|
|
73
83
|
}
|
|
74
84
|
|
|
75
|
-
fun
|
|
85
|
+
internal fun getDependencySubstitutions(
|
|
86
|
+
versionString: String,
|
|
87
|
+
groupString: String = DEFAULT_INTERNAL_PUBLISHING_GROUP
|
|
88
|
+
): List<Triple<String, String, String>> {
|
|
89
|
+
val dependencySubstitution = mutableListOf<Triple<String, String, String>>()
|
|
90
|
+
dependencySubstitution.add(
|
|
91
|
+
Triple(
|
|
92
|
+
"com.facebook.react:react-native",
|
|
93
|
+
"${groupString}:react-android:${versionString}",
|
|
94
|
+
"The react-native artifact was deprecated in favor of react-android due to https://github.com/facebook/react-native/issues/35210."))
|
|
95
|
+
dependencySubstitution.add(
|
|
96
|
+
Triple(
|
|
97
|
+
"com.facebook.react:hermes-engine",
|
|
98
|
+
"${groupString}:hermes-android:${versionString}",
|
|
99
|
+
"The hermes-engine artifact was deprecated in favor of hermes-android due to https://github.com/facebook/react-native/issues/35210."))
|
|
100
|
+
if (groupString != DEFAULT_INTERNAL_PUBLISHING_GROUP) {
|
|
101
|
+
dependencySubstitution.add(
|
|
102
|
+
Triple(
|
|
103
|
+
"com.facebook.react:react-android",
|
|
104
|
+
"${groupString}:react-android:${versionString}",
|
|
105
|
+
"The react-android dependency was modified to use the correct Maven group."))
|
|
106
|
+
dependencySubstitution.add(
|
|
107
|
+
Triple(
|
|
108
|
+
"com.facebook.react:hermes-android",
|
|
109
|
+
"${groupString}:hermes-android:${versionString}",
|
|
110
|
+
"The hermes-android dependency was modified to use the correct Maven group."))
|
|
111
|
+
}
|
|
112
|
+
return dependencySubstitution
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
fun readVersionAndGroupStrings(propertiesFile: File): Pair<String, String> {
|
|
76
116
|
val reactAndroidProperties = Properties()
|
|
77
117
|
propertiesFile.inputStream().use { reactAndroidProperties.load(it) }
|
|
78
|
-
val
|
|
118
|
+
val versionStringFromFile = reactAndroidProperties[INTERNAL_VERSION_NAME] as? String ?: ""
|
|
79
119
|
// If on a nightly, we need to fetch the -SNAPSHOT artifact from Sonatype.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
120
|
+
val versionString =
|
|
121
|
+
if (versionStringFromFile.startsWith("0.0.0") || "-nightly-" in versionStringFromFile) {
|
|
122
|
+
"$versionStringFromFile-SNAPSHOT"
|
|
123
|
+
} else {
|
|
124
|
+
versionStringFromFile
|
|
125
|
+
}
|
|
126
|
+
// Returns Maven group for repos using different group for Maven artifacts
|
|
127
|
+
val groupString =
|
|
128
|
+
reactAndroidProperties[INTERNAL_PUBLISHING_GROUP] as? String
|
|
129
|
+
?: DEFAULT_INTERNAL_PUBLISHING_GROUP
|
|
130
|
+
return Pair(versionString, groupString)
|
|
85
131
|
}
|
|
86
132
|
|
|
87
133
|
fun Project.mavenRepoFromUrl(url: String): MavenArtifactRepository =
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
package com.facebook.react.utils
|
|
9
|
+
|
|
10
|
+
import com.android.build.api.variant.AndroidComponentsExtension
|
|
11
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT
|
|
12
|
+
import org.gradle.api.Action
|
|
13
|
+
import org.gradle.api.JavaVersion
|
|
14
|
+
import org.gradle.api.Project
|
|
15
|
+
import org.gradle.api.plugins.AppliedPlugin
|
|
16
|
+
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
|
|
17
|
+
|
|
18
|
+
internal object JdkConfiguratorUtils {
|
|
19
|
+
/**
|
|
20
|
+
* Function that takes care of configuring the JDK toolchain for all the projects projects. As we
|
|
21
|
+
* do decide the JDK version based on the AGP version that RNGP brings over, here we can safely
|
|
22
|
+
* configure the toolchain to 17.
|
|
23
|
+
*/
|
|
24
|
+
fun configureJavaToolChains(input: Project) {
|
|
25
|
+
// Check at the app level if react.internal.disableJavaVersionAlignment is set.
|
|
26
|
+
if (input.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
input.rootProject.allprojects { project ->
|
|
30
|
+
// Allows every single module to set react.internal.disableJavaVersionAlignment also.
|
|
31
|
+
if (project.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) {
|
|
32
|
+
return@allprojects
|
|
33
|
+
}
|
|
34
|
+
val action =
|
|
35
|
+
Action<AppliedPlugin> {
|
|
36
|
+
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext
|
|
37
|
+
->
|
|
38
|
+
ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
|
|
39
|
+
ext.compileOptions.targetCompatibility = JavaVersion.VERSION_17
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
project.pluginManager.withPlugin("com.android.application", action)
|
|
43
|
+
project.pluginManager.withPlugin("com.android.library", action)
|
|
44
|
+
project.pluginManager.withPlugin("org.jetbrains.kotlin.android") {
|
|
45
|
+
project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17)
|
|
46
|
+
}
|
|
47
|
+
project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
|
48
|
+
project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -14,7 +14,7 @@ import java.io.File
|
|
|
14
14
|
object JsonUtils {
|
|
15
15
|
private val gsonConverter = Gson()
|
|
16
16
|
|
|
17
|
-
fun
|
|
17
|
+
fun fromPackageJson(input: File): ModelPackageJson? =
|
|
18
18
|
input.bufferedReader().use {
|
|
19
19
|
runCatching { gsonConverter.fromJson(it, ModelPackageJson::class.java) }.getOrNull()
|
|
20
20
|
}
|
|
@@ -20,7 +20,7 @@ internal object NdkConfiguratorUtils {
|
|
|
20
20
|
fun configureReactNativeNdk(project: Project, extension: ReactExtension) {
|
|
21
21
|
project.pluginManager.withPlugin("com.android.application") {
|
|
22
22
|
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
|
|
23
|
-
if (!project.isNewArchEnabled) {
|
|
23
|
+
if (!project.isNewArchEnabled(extension)) {
|
|
24
24
|
// For Old Arch, we don't need to setup the NDK
|
|
25
25
|
return@finalizeDsl
|
|
26
26
|
}
|
|
@@ -40,16 +40,22 @@ internal object NdkConfiguratorUtils {
|
|
|
40
40
|
// Parameters should be provided in an additive manner (do not override what
|
|
41
41
|
// the user provided, but allow for sensible defaults).
|
|
42
42
|
val cmakeArgs = ext.defaultConfig.externalNativeBuild.cmake.arguments
|
|
43
|
-
if ("-DPROJECT_BUILD_DIR"
|
|
44
|
-
cmakeArgs.add("-DPROJECT_BUILD_DIR=${project.
|
|
43
|
+
if (cmakeArgs.none { it.startsWith("-DPROJECT_BUILD_DIR") }) {
|
|
44
|
+
cmakeArgs.add("-DPROJECT_BUILD_DIR=${project.layout.buildDirectory.get().asFile}")
|
|
45
45
|
}
|
|
46
|
-
if ("-DREACT_ANDROID_DIR"
|
|
46
|
+
if (cmakeArgs.none { it.startsWith("-DREACT_ANDROID_DIR") }) {
|
|
47
47
|
cmakeArgs.add(
|
|
48
48
|
"-DREACT_ANDROID_DIR=${extension.reactNativeDir.file("ReactAndroid").get().asFile}")
|
|
49
49
|
}
|
|
50
|
-
if ("-DANDROID_STL"
|
|
50
|
+
if (cmakeArgs.none { it.startsWith("-DANDROID_STL") }) {
|
|
51
51
|
cmakeArgs.add("-DANDROID_STL=c++_shared")
|
|
52
52
|
}
|
|
53
|
+
// Due to the new NDK toolchain file, the C++ flags gets overridden between compilation
|
|
54
|
+
// units. This is causing some libraries to don't be compiled with -DANDROID and other
|
|
55
|
+
// crucial flags. This can be revisited once we bump to NDK 25/26
|
|
56
|
+
if (cmakeArgs.none { it.startsWith("-DANDROID_USE_LEGACY_TOOLCHAIN_FILE") }) {
|
|
57
|
+
cmakeArgs.add("-DANDROID_USE_LEGACY_TOOLCHAIN_FILE=ON")
|
|
58
|
+
}
|
|
53
59
|
|
|
54
60
|
val architectures = project.getReactNativeArchitectures()
|
|
55
61
|
// abiFilters are split ABI are not compatible each other, so we set the abiFilters
|
|
@@ -68,11 +74,12 @@ internal object NdkConfiguratorUtils {
|
|
|
68
74
|
*/
|
|
69
75
|
fun configureNewArchPackagingOptions(
|
|
70
76
|
project: Project,
|
|
71
|
-
|
|
77
|
+
extension: ReactExtension,
|
|
78
|
+
variant: Variant
|
|
72
79
|
) {
|
|
73
|
-
if (!project.isNewArchEnabled) {
|
|
80
|
+
if (!project.isNewArchEnabled(extension)) {
|
|
74
81
|
// For Old Arch, we set a pickFirst only on libraries that we know are
|
|
75
|
-
// clashing with our direct dependencies (FBJNI
|
|
82
|
+
// clashing with our direct dependencies (mainly FBJNI and Hermes).
|
|
76
83
|
variant.packaging.jniLibs.pickFirsts.addAll(
|
|
77
84
|
listOf(
|
|
78
85
|
"**/libfbjni.so",
|
|
@@ -101,6 +108,7 @@ internal object NdkConfiguratorUtils {
|
|
|
101
108
|
"**/libreact_render_graphics.so",
|
|
102
109
|
"**/libreact_render_imagemanager.so",
|
|
103
110
|
"**/libreact_render_mapbuffer.so",
|
|
111
|
+
"**/libreact_utils.so",
|
|
104
112
|
"**/librrc_image.so",
|
|
105
113
|
"**/librrc_legacyviewmanagerinterop.so",
|
|
106
114
|
"**/librrc_view.so",
|
|
@@ -103,8 +103,8 @@ private fun detectCliFile(reactNativeRoot: File, preconfiguredCliFile: File?): F
|
|
|
103
103
|
error(
|
|
104
104
|
"""
|
|
105
105
|
Couldn't determine CLI location!
|
|
106
|
-
|
|
107
|
-
Please set `react { cliFile = file(...) }` inside your
|
|
106
|
+
|
|
107
|
+
Please set `react { cliFile = file(...) }` inside your
|
|
108
108
|
build.gradle to the path of the react-native cli.js file.
|
|
109
109
|
This file typically resides in `node_modules/react-native/cli.js`
|
|
110
110
|
"""
|
|
@@ -224,7 +224,7 @@ internal fun readPackageJsonFile(
|
|
|
224
224
|
rootProperty: DirectoryProperty
|
|
225
225
|
): ModelPackageJson? {
|
|
226
226
|
val packageJson = findPackageJsonFile(project, rootProperty)
|
|
227
|
-
return packageJson?.let { JsonUtils.
|
|
227
|
+
return packageJson?.let { JsonUtils.fromPackageJson(it) }
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
private const val HERMESC_IN_REACT_NATIVE_DIR = "node_modules/react-native/sdks/hermesc/%OS-BIN%/"
|
|
@@ -7,29 +7,46 @@
|
|
|
7
7
|
|
|
8
8
|
package com.facebook.react.utils
|
|
9
9
|
|
|
10
|
+
import com.facebook.react.ReactExtension
|
|
10
11
|
import com.facebook.react.model.ModelPackageJson
|
|
11
12
|
import com.facebook.react.utils.KotlinStdlibCompatUtils.lowercaseCompat
|
|
12
13
|
import com.facebook.react.utils.KotlinStdlibCompatUtils.toBooleanStrictOrNullCompat
|
|
14
|
+
import com.facebook.react.utils.PropertyUtils.HERMES_ENABLED
|
|
15
|
+
import com.facebook.react.utils.PropertyUtils.NEW_ARCH_ENABLED
|
|
16
|
+
import com.facebook.react.utils.PropertyUtils.REACT_NATIVE_ARCHITECTURES
|
|
17
|
+
import com.facebook.react.utils.PropertyUtils.SCOPED_HERMES_ENABLED
|
|
18
|
+
import com.facebook.react.utils.PropertyUtils.SCOPED_NEW_ARCH_ENABLED
|
|
19
|
+
import com.facebook.react.utils.PropertyUtils.SCOPED_REACT_NATIVE_ARCHITECTURES
|
|
20
|
+
import java.io.File
|
|
13
21
|
import org.gradle.api.Project
|
|
14
22
|
import org.gradle.api.file.DirectoryProperty
|
|
15
23
|
|
|
16
24
|
internal object ProjectUtils {
|
|
17
|
-
internal val Project.isNewArchEnabled: Boolean
|
|
18
|
-
get() =
|
|
19
|
-
project.hasProperty("newArchEnabled") &&
|
|
20
|
-
project.property("newArchEnabled").toString().toBoolean()
|
|
21
25
|
|
|
22
26
|
const val HERMES_FALLBACK = true
|
|
23
27
|
|
|
28
|
+
internal fun Project.isNewArchEnabled(extension: ReactExtension): Boolean {
|
|
29
|
+
return (project.hasProperty(NEW_ARCH_ENABLED) &&
|
|
30
|
+
project.property(NEW_ARCH_ENABLED).toString().toBoolean()) ||
|
|
31
|
+
(project.hasProperty(SCOPED_NEW_ARCH_ENABLED) &&
|
|
32
|
+
project.property(SCOPED_NEW_ARCH_ENABLED).toString().toBoolean()) ||
|
|
33
|
+
shouldEnableNewArchForReactNativeVersion(project.reactNativeDir(extension))
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
internal val Project.isHermesEnabled: Boolean
|
|
25
37
|
get() =
|
|
26
|
-
if (project.hasProperty(
|
|
38
|
+
if (project.hasProperty(HERMES_ENABLED) || project.hasProperty(SCOPED_HERMES_ENABLED)) {
|
|
39
|
+
val propertyString =
|
|
40
|
+
if (project.hasProperty(HERMES_ENABLED)) {
|
|
41
|
+
HERMES_ENABLED
|
|
42
|
+
} else {
|
|
43
|
+
SCOPED_HERMES_ENABLED
|
|
44
|
+
}
|
|
27
45
|
project
|
|
28
|
-
.property(
|
|
46
|
+
.property(propertyString)
|
|
29
47
|
.toString()
|
|
30
48
|
.lowercaseCompat()
|
|
31
|
-
.toBooleanStrictOrNullCompat()
|
|
32
|
-
?: true
|
|
49
|
+
.toBooleanStrictOrNullCompat() ?: true
|
|
33
50
|
} else if (project.extensions.extraProperties.has("react")) {
|
|
34
51
|
@Suppress("UNCHECKED_CAST")
|
|
35
52
|
val reactMap = project.extensions.extraProperties.get("react") as? Map<String, Any?>
|
|
@@ -53,10 +70,48 @@ internal object ProjectUtils {
|
|
|
53
70
|
|
|
54
71
|
internal fun Project.getReactNativeArchitectures(): List<String> {
|
|
55
72
|
val architectures = mutableListOf<String>()
|
|
56
|
-
if (project.hasProperty(
|
|
57
|
-
val architecturesString = project.property(
|
|
73
|
+
if (project.hasProperty(REACT_NATIVE_ARCHITECTURES)) {
|
|
74
|
+
val architecturesString = project.property(REACT_NATIVE_ARCHITECTURES).toString()
|
|
75
|
+
architectures.addAll(architecturesString.split(",").filter { it.isNotBlank() })
|
|
76
|
+
} else if (project.hasProperty(SCOPED_REACT_NATIVE_ARCHITECTURES)) {
|
|
77
|
+
val architecturesString = project.property(SCOPED_REACT_NATIVE_ARCHITECTURES).toString()
|
|
58
78
|
architectures.addAll(architecturesString.split(",").filter { it.isNotBlank() })
|
|
59
79
|
}
|
|
60
80
|
return architectures
|
|
61
81
|
}
|
|
82
|
+
|
|
83
|
+
internal fun Project.reactNativeDir(extension: ReactExtension): String =
|
|
84
|
+
extension.reactNativeDir.get().asFile.absolutePath
|
|
85
|
+
|
|
86
|
+
internal fun shouldEnableNewArchForReactNativeVersion(reactNativeDir: String): Boolean {
|
|
87
|
+
val packageJsonFile = File(reactNativeDir, "package.json")
|
|
88
|
+
if (!packageJsonFile.exists()) {
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
val rnPackageJson = JsonUtils.fromPackageJson(packageJsonFile)
|
|
93
|
+
if (rnPackageJson == null) {
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// This regex describe the version syntax for React Native in the shape of
|
|
98
|
+
// major.minor.patch[-<prerelease>[[-.]k]]
|
|
99
|
+
// Where
|
|
100
|
+
// major is a number
|
|
101
|
+
// minor is a number
|
|
102
|
+
// patch is a number
|
|
103
|
+
// <prerelease>[-.]k is optional, but if present is preceeded by a `-`
|
|
104
|
+
// the <prerelease> tag is a string.
|
|
105
|
+
// it can be followed by `-` or `.` and k is a number.
|
|
106
|
+
val regex = """^(\d+)\.(\d+)\.(\d+)(?:-(\w+(?:[-.]\d+)?))?$""".toRegex()
|
|
107
|
+
|
|
108
|
+
val matchResult = regex.find(rnPackageJson.version)
|
|
109
|
+
|
|
110
|
+
if (matchResult == null) {
|
|
111
|
+
return false
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
val major = matchResult.groupValues[1].toInt()
|
|
115
|
+
return major > 0 && major < 1000
|
|
116
|
+
}
|
|
62
117
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
package com.facebook.react.utils
|
|
9
|
+
|
|
10
|
+
/** Collection of all the Gradle Properties that are accepted by React Native Gradle Plugin. */
|
|
11
|
+
object PropertyUtils {
|
|
12
|
+
|
|
13
|
+
/** Public property that toggles the New Architecture */
|
|
14
|
+
const val NEW_ARCH_ENABLED = "newArchEnabled"
|
|
15
|
+
const val SCOPED_NEW_ARCH_ENABLED = "react.newArchEnabled"
|
|
16
|
+
|
|
17
|
+
/** Public property that toggles the New Architecture */
|
|
18
|
+
const val HERMES_ENABLED = "hermesEnabled"
|
|
19
|
+
const val SCOPED_HERMES_ENABLED = "react.hermesEnabled"
|
|
20
|
+
|
|
21
|
+
/** Public property that allows to control which architectures to build for React Native. */
|
|
22
|
+
const val REACT_NATIVE_ARCHITECTURES = "reactNativeArchitectures"
|
|
23
|
+
const val SCOPED_REACT_NATIVE_ARCHITECTURES = "react.nativeArchitectures"
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Internal Property that acts as a killswitch to configure the JDK version and align it for app
|
|
27
|
+
* and all the libraries.
|
|
28
|
+
*/
|
|
29
|
+
const val INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT = "react.internal.disableJavaVersionAlignment"
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Internal Property that allows to specify a local Maven repository to use for React Native
|
|
33
|
+
* artifacts It's used on CI to test templates against a version of React Native built on the fly.
|
|
34
|
+
*/
|
|
35
|
+
const val INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO = "react.internal.mavenLocalRepo"
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Internal property used to specify where the Windows Bash executable is located. This is useful
|
|
39
|
+
* for contributors who are running Windows on their machine.
|
|
40
|
+
*/
|
|
41
|
+
const val INTERNAL_REACT_WINDOWS_BASH = "react.internal.windowsBashPath"
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Internal property to force the build to use Hermes from the latest nightly. This speeds up the
|
|
45
|
+
* build at the cost of not testing the latest integration against Hermes.
|
|
46
|
+
*/
|
|
47
|
+
const val INTERNAL_USE_HERMES_NIGHTLY = "react.internal.useHermesNightly"
|
|
48
|
+
|
|
49
|
+
/** Internal property used to override the publishing group for the React Native artifacts. */
|
|
50
|
+
const val INTERNAL_PUBLISHING_GROUP = "react.internal.publishingGroup"
|
|
51
|
+
const val DEFAULT_INTERNAL_PUBLISHING_GROUP = "com.facebook.react"
|
|
52
|
+
|
|
53
|
+
/** Internal property used to control the version name of React Native */
|
|
54
|
+
const val INTERNAL_VERSION_NAME = "VERSION_NAME"
|
|
55
|
+
}
|