Skip to content

Commit 0870c3d

Browse files
cortinicokikoso
authored andcommitted
RNGP - Make sure the newArchEnabled is set to true for all the libs (facebook#53138)
Summary: Pull Request resolved: facebook#53138 Without this patch, library could break if the user removes the `newArchEnabled=` property from the `gradle.properties` file. With this patch instead we hardcode the property to true, so all the libraries can consume it if they wish. Changelog: [Internal] [Changed] - Reviewed By: cipolleschi Differential Revision: D79805857 fbshipit-source-id: 88dda707a0d80ac79e96c955ded2ef0823f3d3ff
1 parent a1b29b0 commit 0870c3d

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import com.facebook.react.utils.JdkConfiguratorUtils.configureJavaToolChains
2929
import com.facebook.react.utils.JsonUtils
3030
import com.facebook.react.utils.NdkConfiguratorUtils.configureReactNativeNdk
3131
import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
32-
import com.facebook.react.utils.PropertyUtils
3332
import com.facebook.react.utils.findPackageJsonFile
3433
import java.io.File
3534
import kotlin.system.exitProcess
@@ -43,7 +42,6 @@ import org.gradle.internal.jvm.Jvm
4342
class ReactPlugin : Plugin<Project> {
4443
override fun apply(project: Project) {
4544
checkJvmVersion(project)
46-
checkLegacyArchProperty(project)
4745
val extension = project.extensions.create("react", ReactExtension::class.java, project)
4846

4947
// We register a private extension on the rootProject so that project wide configs
@@ -116,30 +114,6 @@ class ReactPlugin : Plugin<Project> {
116114
}
117115
}
118116

119-
private fun checkLegacyArchProperty(project: Project) {
120-
if ((project.hasProperty(PropertyUtils.NEW_ARCH_ENABLED) &&
121-
!project.property(PropertyUtils.NEW_ARCH_ENABLED).toString().toBoolean()) ||
122-
(project.hasProperty(PropertyUtils.SCOPED_NEW_ARCH_ENABLED) &&
123-
!project.property(PropertyUtils.SCOPED_NEW_ARCH_ENABLED).toString().toBoolean())) {
124-
project.logger.error(
125-
"""
126-
127-
********************************************************************************
128-
129-
WARNING: Setting `newArchEnabled=false` in your `gradle.properties` file is not
130-
supported anymore since React Native 0.82.
131-
132-
You can remove the line from your `gradle.properties` file.
133-
134-
The application will run with the New Architecture enabled by default.
135-
136-
********************************************************************************
137-
138-
"""
139-
.trimIndent())
140-
}
141-
}
142-
143117
/** This function configures Android resources - in this case just the bundle */
144118
private fun configureResources(project: Project, reactExtension: ReactExtension) {
145119
project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java).finalizeDsl {

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactRootProjectPlugin.kt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
package com.facebook.react
99

10+
import com.facebook.react.utils.PropertyUtils
1011
import org.gradle.api.Plugin
1112
import org.gradle.api.Project
13+
import org.jetbrains.kotlin.gradle.plugin.extraProperties
1214

1315
/**
1416
* Gradle plugin applied to the `android/build.gradle` file.
@@ -18,13 +20,25 @@ import org.gradle.api.Project
1820
*/
1921
class ReactRootProjectPlugin : Plugin<Project> {
2022
override fun apply(project: Project) {
21-
project.subprojects {
23+
checkLegacyArchProperty(project)
24+
project.subprojects { subproject ->
2225
// As the :app project (i.e. ReactPlugin) configures both namespaces and JVM toolchains
2326
// for libraries, its evaluation must happen before the libraries' evaluation.
2427
// Eventually the configuration of namespace/JVM toolchain can be moved inside this plugin.
25-
if (it.path != ":app") {
26-
it.evaluationDependsOn(":app")
28+
if (subproject.path != ":app") {
29+
subproject.evaluationDependsOn(":app")
2730
}
31+
// We set the New Architecture properties to true for all subprojects. So that
32+
// libraries don't need to be modified and can keep on using the isNewArchEnabled()
33+
// function to check if property is set.
34+
if (subproject.hasProperty(PropertyUtils.SCOPED_NEW_ARCH_ENABLED)) {
35+
subproject.setProperty(PropertyUtils.SCOPED_NEW_ARCH_ENABLED, "true")
36+
}
37+
if (subproject.hasProperty(PropertyUtils.NEW_ARCH_ENABLED)) {
38+
subproject.setProperty(PropertyUtils.NEW_ARCH_ENABLED, "true")
39+
}
40+
subproject.extraProperties.set(PropertyUtils.NEW_ARCH_ENABLED, "true")
41+
subproject.extraProperties.set(PropertyUtils.SCOPED_NEW_ARCH_ENABLED, "true")
2842
}
2943
// We need to make sure that `:app:preBuild` task depends on all other subprojects' preBuild
3044
// tasks. This is necessary in order to have all the codegen generated code before the CMake
@@ -43,4 +57,27 @@ class ReactRootProjectPlugin : Plugin<Project> {
4357
}
4458
}
4559
}
60+
61+
private fun checkLegacyArchProperty(project: Project) {
62+
if ((project.hasProperty(PropertyUtils.NEW_ARCH_ENABLED) &&
63+
!project.property(PropertyUtils.NEW_ARCH_ENABLED).toString().toBoolean()) ||
64+
(project.hasProperty(PropertyUtils.SCOPED_NEW_ARCH_ENABLED) &&
65+
!project.property(PropertyUtils.SCOPED_NEW_ARCH_ENABLED).toString().toBoolean())) {
66+
project.logger.error(
67+
"""
68+
********************************************************************************
69+
70+
WARNING: Setting `newArchEnabled=false` in your `gradle.properties` file is not
71+
supported anymore since React Native 0.82.
72+
73+
You can remove the line from your `gradle.properties` file.
74+
75+
The application will run with the New Architecture enabled by default.
76+
77+
********************************************************************************
78+
79+
"""
80+
.trimIndent())
81+
}
82+
}
4683
}

0 commit comments

Comments
 (0)