Skip to content

Commit d5d21d0

Browse files
cortinicofacebook-github-bot
authored andcommitted
Remove possibility to newArchEnabled=false in 0.82 (#53025)
Summary: Pull Request resolved: #53025 It's now time to say goodbye to the Legacy Architecture :') This change hardcodes the `newArchEnabled` property to true, and warns the users if they're attempting to set it to false. Changelog: [Android] [Breaking] - Remove possibility to newArchEnabled=false in 0.82 Reviewed By: cipolleschi Differential Revision: D78560296 fbshipit-source-id: ccfc45d2f7f21cc20e063cb901d76be3d41458d6
1 parent de5093c commit d5d21d0

File tree

7 files changed

+59
-124
lines changed

7 files changed

+59
-124
lines changed

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

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import com.facebook.react.utils.DependencyUtils.readVersionAndGroupStrings
2828
import com.facebook.react.utils.JdkConfiguratorUtils.configureJavaToolChains
2929
import com.facebook.react.utils.JsonUtils
3030
import com.facebook.react.utils.NdkConfiguratorUtils.configureReactNativeNdk
31-
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
3231
import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
32+
import com.facebook.react.utils.PropertyUtils
3333
import com.facebook.react.utils.findPackageJsonFile
3434
import java.io.File
3535
import kotlin.system.exitProcess
@@ -43,6 +43,7 @@ import org.gradle.internal.jvm.Jvm
4343
class ReactPlugin : Plugin<Project> {
4444
override fun apply(project: Project) {
4545
checkJvmVersion(project)
46+
checkLegacyArchProperty(project)
4647
val extension = project.extensions.create("react", ReactExtension::class.java, project)
4748

4849
// We register a private extension on the rootProject so that project wide configs
@@ -115,6 +116,30 @@ class ReactPlugin : Plugin<Project> {
115116
}
116117
}
117118

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+
118143
/** This function configures Android resources - in this case just the bundle */
119144
private fun configureResources(project: Project, reactExtension: ReactExtension) {
120145
project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java).finalizeDsl {
@@ -271,19 +296,17 @@ class ReactPlugin : Plugin<Project> {
271296
task.generatedOutputDirectory.set(generatedAutolinkingJavaDir)
272297
}
273298

274-
if (project.isNewArchEnabled(extension)) {
275-
// For New Arch, we also need to generate code for C++ Autolinking
276-
val generateAutolinkingNewArchitectureFilesTask =
277-
project.tasks.register(
278-
"generateAutolinkingNewArchitectureFiles",
279-
GenerateAutolinkingNewArchitecturesFileTask::class.java) { task ->
280-
task.autolinkInputFile.set(rootGeneratedAutolinkingFile)
281-
task.generatedOutputDirectory.set(generatedAutolinkingJniDir)
282-
}
283-
project.tasks
284-
.named("preBuild", Task::class.java)
285-
.dependsOn(generateAutolinkingNewArchitectureFilesTask)
286-
}
299+
// We also need to generate code for C++ Autolinking
300+
val generateAutolinkingNewArchitectureFilesTask =
301+
project.tasks.register(
302+
"generateAutolinkingNewArchitectureFiles",
303+
GenerateAutolinkingNewArchitecturesFileTask::class.java) { task ->
304+
task.autolinkInputFile.set(rootGeneratedAutolinkingFile)
305+
task.generatedOutputDirectory.set(generatedAutolinkingJniDir)
306+
}
307+
project.tasks
308+
.named("preBuild", Task::class.java)
309+
.dependsOn(generateAutolinkingNewArchitectureFilesTask)
287310

288311
// We let generateAutolinkingPackageList and generateEntryPoint depend on the preBuild task so
289312
// it's executed before

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import com.android.build.gradle.LibraryExtension
1313
import com.facebook.react.ReactExtension
1414
import com.facebook.react.utils.ProjectUtils.isEdgeToEdgeEnabled
1515
import com.facebook.react.utils.ProjectUtils.isHermesEnabled
16-
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
1716
import java.io.File
1817
import java.net.Inet4Address
1918
import java.net.NetworkInterface
@@ -65,10 +64,7 @@ internal object AgpConfiguratorUtils {
6564
.getByType(ApplicationAndroidComponentsExtension::class.java)
6665
.finalizeDsl { ext ->
6766
ext.buildFeatures.buildConfig = true
68-
ext.defaultConfig.buildConfigField(
69-
"boolean",
70-
"IS_NEW_ARCHITECTURE_ENABLED",
71-
project.isNewArchEnabled(extension).toString())
67+
ext.defaultConfig.buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true")
7268
ext.defaultConfig.buildConfigField(
7369
"boolean", "IS_HERMES_ENABLED", project.isHermesEnabled.toString())
7470
ext.defaultConfig.buildConfigField(

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

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import com.android.build.api.variant.ApplicationAndroidComponentsExtension
1111
import com.android.build.api.variant.Variant
1212
import com.facebook.react.ReactExtension
1313
import com.facebook.react.utils.ProjectUtils.getReactNativeArchitectures
14-
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
1514
import java.io.File
1615
import org.gradle.api.Project
1716

@@ -21,10 +20,6 @@ internal object NdkConfiguratorUtils {
2120
project.pluginManager.withPlugin("com.android.application") {
2221
project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java).finalizeDsl {
2322
ext ->
24-
if (!project.isNewArchEnabled(extension)) {
25-
// For Old Arch, we don't need to setup the NDK
26-
return@finalizeDsl
27-
}
2823
// We enable prefab so users can consume .so/headers from ReactAndroid and hermes-engine
2924
// .aar
3025
ext.buildFeatures.prefab = true
@@ -78,29 +73,19 @@ internal object NdkConfiguratorUtils {
7873
extension: ReactExtension,
7974
variant: Variant
8075
) {
81-
if (!project.isNewArchEnabled(extension)) {
82-
// For Old Arch, we set a pickFirst only on libraries that we know are
83-
// clashing with our direct dependencies (mainly FBJNI and Hermes).
84-
variant.packaging.jniLibs.pickFirsts.addAll(
85-
listOf(
86-
"**/libfbjni.so",
87-
"**/libc++_shared.so",
88-
))
89-
} else {
90-
// We set some packagingOptions { pickFirst ... } for our users for libraries we own.
91-
variant.packaging.jniLibs.pickFirsts.addAll(
92-
listOf(
93-
// This is the .so provided by FBJNI via prefab
94-
"**/libfbjni.so",
95-
// Those are prefab libraries we distribute via ReactAndroid
96-
// Due to a bug in AGP, they fire a warning on console as both the JNI
97-
// and the prefab .so files gets considered.
98-
"**/libreactnative.so",
99-
"**/libjsi.so",
100-
// AGP will give priority of libc++_shared coming from App modules.
101-
"**/libc++_shared.so",
102-
))
103-
}
76+
// We set some packagingOptions { pickFirst ... } for our users for libraries we own.
77+
variant.packaging.jniLibs.pickFirsts.addAll(
78+
listOf(
79+
// This is the .so provided by FBJNI via prefab
80+
"**/libfbjni.so",
81+
// Those are prefab libraries we distribute via ReactAndroid
82+
// Due to a bug in AGP, they fire a warning on console as both the JNI
83+
// and the prefab .so files gets considered.
84+
"**/libreactnative.so",
85+
"**/libjsi.so",
86+
// AGP will give priority of libc++_shared coming from App modules.
87+
"**/libc++_shared.so",
88+
))
10489
}
10590

10691
/**

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ import com.facebook.react.utils.KotlinStdlibCompatUtils.lowercaseCompat
1313
import com.facebook.react.utils.KotlinStdlibCompatUtils.toBooleanStrictOrNullCompat
1414
import com.facebook.react.utils.PropertyUtils.EDGE_TO_EDGE_ENABLED
1515
import com.facebook.react.utils.PropertyUtils.HERMES_ENABLED
16-
import com.facebook.react.utils.PropertyUtils.NEW_ARCH_ENABLED
1716
import com.facebook.react.utils.PropertyUtils.REACT_NATIVE_ARCHITECTURES
1817
import com.facebook.react.utils.PropertyUtils.SCOPED_EDGE_TO_EDGE_ENABLED
1918
import com.facebook.react.utils.PropertyUtils.SCOPED_HERMES_ENABLED
20-
import com.facebook.react.utils.PropertyUtils.SCOPED_NEW_ARCH_ENABLED
2119
import com.facebook.react.utils.PropertyUtils.SCOPED_REACT_NATIVE_ARCHITECTURES
2220
import com.facebook.react.utils.PropertyUtils.SCOPED_USE_THIRD_PARTY_JSC
2321
import com.facebook.react.utils.PropertyUtils.USE_THIRD_PARTY_JSC
@@ -28,12 +26,7 @@ internal object ProjectUtils {
2826

2927
const val HERMES_FALLBACK = true
3028

31-
internal fun Project.isNewArchEnabled(extension: ReactExtension): Boolean {
32-
return (project.hasProperty(NEW_ARCH_ENABLED) &&
33-
project.property(NEW_ARCH_ENABLED).toString().toBoolean()) ||
34-
(project.hasProperty(SCOPED_NEW_ARCH_ENABLED) &&
35-
project.property(SCOPED_NEW_ARCH_ENABLED).toString().toBoolean())
36-
}
29+
internal fun Project.isNewArchEnabled(): Boolean = true
3730

3831
internal val Project.isHermesEnabled: Boolean
3932
get() =

packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/ProjectUtilsTest.kt

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -27,70 +27,8 @@ class ProjectUtilsTest {
2727
@get:Rule val tempFolder = TemporaryFolder()
2828

2929
@Test
30-
fun isNewArchEnabled_returnsFalseByDefault() {
31-
val project = createProject()
32-
val extension = TestReactExtension(project)
33-
assertThat(createProject().isNewArchEnabled(extension)).isFalse()
34-
}
35-
36-
@Test
37-
fun isNewArchEnabled_withDisabled_returnsFalse() {
38-
val project = createProject()
39-
project.extensions.extraProperties.set("newArchEnabled", "false")
40-
val extension = TestReactExtension(project)
41-
assertThat(project.isNewArchEnabled(extension)).isFalse()
42-
}
43-
44-
@Test
45-
fun isNewArchEnabled_withEnabled_returnsTrue() {
46-
val project = createProject()
47-
project.extensions.extraProperties.set("newArchEnabled", "true")
48-
val extension = TestReactExtension(project)
49-
assertThat(project.isNewArchEnabled(extension)).isTrue()
50-
}
51-
52-
@Test
53-
fun isNewArchEnabled_withInvalid_returnsFalse() {
54-
val project = createProject()
55-
project.extensions.extraProperties.set("newArchEnabled", "¯\\_(ツ)_/¯")
56-
val extension = TestReactExtension(project)
57-
assertThat(project.isNewArchEnabled(extension)).isFalse()
58-
}
59-
60-
@Test
61-
fun isNewArchEnabled_withRNVersion0_returnFalse() {
62-
val project = createProject()
63-
val extension = TestReactExtension(project)
64-
File(tempFolder.root, "package.json").apply {
65-
writeText(
66-
// language=json
67-
"""
68-
{
69-
"version": "0.73.0"
70-
}
71-
"""
72-
.trimIndent())
73-
}
74-
extension.reactNativeDir.set(tempFolder.root)
75-
assertThat(project.isNewArchEnabled(extension)).isFalse()
76-
}
77-
78-
@Test
79-
fun isNewArchEnabled_withRNVersion1000_returnFalse() {
80-
val project = createProject()
81-
val extension = TestReactExtension(project)
82-
File(tempFolder.root, "package.json").apply {
83-
writeText(
84-
// language=json
85-
"""
86-
{
87-
"version": "1000.0.0"
88-
}
89-
"""
90-
.trimIndent())
91-
}
92-
extension.reactNativeDir.set(tempFolder.root)
93-
assertThat(project.isNewArchEnabled(extension)).isFalse()
30+
fun isNewArchEnabled_alwaysReturnsTrue() {
31+
assertThat(createProject().isNewArchEnabled()).isTrue()
9432
}
9533

9634
@Test

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactNativeHost.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ protected constructor(
4242
if (isNewArchEnabled) {
4343
DefaultTurboModuleManagerDelegate.Builder()
4444
} else {
45-
null
45+
error(
46+
"Overriding isNewArchEnabled to false is not supported anymore since React Native 0.82. Please check your MainApplication.kt file, and remove the override for `isNewArchEnabled`.")
4647
}
4748

4849
override fun getUIManagerProvider(): UIManagerProvider? =
@@ -69,7 +70,8 @@ protected constructor(
6970
.createUIManager(reactApplicationContext)
7071
}
7172
} else {
72-
null
73+
error(
74+
"Overriding isNewArchEnabled to false is not supported anymore since React Native 0.82. Please check your MainApplication.kt file, and remove the override for `isNewArchEnabled`.")
7375
}
7476

7577
override fun clear() {
@@ -86,7 +88,7 @@ protected constructor(
8688
* If false, the app will not attempt to load the New Architecture modules.
8789
*/
8890
protected open val isNewArchEnabled: Boolean
89-
get() = false
91+
get() = true
9092

9193
/**
9294
* Returns whether the user wants to use Hermes.

private/helloworld/android/app/src/main/java/com/helloworld/MainApplication.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class MainApplication : Application(), ReactApplication {
3030
override fun getJSMainModuleName(): String = "index"
3131

3232
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
33-
34-
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
3533
}
3634

3735
override val reactHost: ReactHost

0 commit comments

Comments
 (0)