Skip to content

Commit bbcf421

Browse files
authored
feat: enable New Arch by default in new projects (#2434)
1 parent e9fa6f7 commit bbcf421

File tree

4 files changed

+204
-28
lines changed

4 files changed

+204
-28
lines changed

scripts/configure.mjs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import {
1919
appManifest,
2020
buildGradle,
21+
gradleProperties,
2122
podfile,
2223
serialize,
2324
settingsGradle,
@@ -268,6 +269,8 @@ export const getConfig = (() => {
268269
path.dirname(require.resolve("react-native/template/package.json"))
269270
);
270271

272+
const targetVersionNum = toVersionNumber(targetVersion);
273+
271274
configuration = {
272275
common: {
273276
files: {
@@ -343,22 +346,15 @@ export const getConfig = (() => {
343346
"gradle-wrapper.properties"
344347
);
345348
const props = readTextFile(gradleWrapperProperties);
346-
if (toVersionNumber(targetVersion) < v(0, 73, 0)) {
349+
if (targetVersionNum < v(0, 73, 0)) {
347350
return props.replace(
348351
/gradle-[.0-9]*-bin\.zip/,
349352
"gradle-7.6.4-bin.zip"
350353
);
351354
}
352355
return props;
353356
})(),
354-
"gradle.properties": {
355-
source: path.join(
356-
testAppPath,
357-
"example",
358-
"android",
359-
"gradle.properties"
360-
),
361-
},
357+
"gradle.properties": gradleProperties(targetVersionNum),
362358
gradlew: {
363359
source: path.join(testAppPath, "example", "android", "gradlew"),
364360
},
@@ -382,7 +378,7 @@ export const getConfig = (() => {
382378
},
383379
ios: {
384380
files: {
385-
Podfile: podfile(name, ""),
381+
Podfile: podfile(name, "", targetVersionNum),
386382
},
387383
oldFiles: [
388384
"Podfile.lock",
@@ -399,7 +395,7 @@ export const getConfig = (() => {
399395
},
400396
macos: {
401397
files: {
402-
Podfile: podfile(name, "macos/"),
398+
Podfile: podfile(name, "macos/", targetVersionNum),
403399
},
404400
oldFiles: [
405401
"Podfile.lock",
@@ -416,7 +412,7 @@ export const getConfig = (() => {
416412
},
417413
visionos: {
418414
files: {
419-
Podfile: podfile(name, "visionos/"),
415+
Podfile: podfile(name, "visionos/", targetVersionNum),
420416
},
421417
oldFiles: [
422418
"Podfile.lock",

scripts/template.mjs

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @ts-check
2+
import { v } from "./helpers.js";
23

34
/**
45
* Joins all specified lines into a single string.
@@ -96,12 +97,87 @@ export function buildGradle() {
9697
);
9798
}
9899

100+
/**
101+
* @param {number} targetVersion Target React Native version
102+
* @returns {string}
103+
*/
104+
export function gradleProperties(targetVersion) {
105+
// https://github.com/facebook/react-native/commit/14ccf6bc9c40a51e913bb89a67b114f035bf77cd
106+
const enableJetifier = targetVersion < v(0, 75, 0) ? "" : "#";
107+
// https://reactnative.dev/blog/2024/10/23/the-new-architecture-is-here
108+
const enableNewArch = targetVersion >= v(0, 76, 0) ? "" : "#";
109+
return join(
110+
"# Project-wide Gradle settings.",
111+
"",
112+
"# IDE (e.g. Android Studio) users:",
113+
"# Gradle settings configured through the IDE *will override*",
114+
"# any settings specified in this file.",
115+
"",
116+
"# For more details on how to configure your build environment visit",
117+
"# http://www.gradle.org/docs/current/userguide/build_environment.html",
118+
"",
119+
"# Specifies the JVM arguments used for the Gradle Daemon. The setting is",
120+
"# particularly useful for configuring JVM memory settings for build performance.",
121+
"# This does not affect the JVM settings for the Gradle client VM.",
122+
"# The default is `-Xmx512m -XX:MaxMetaspaceSize=256m`.",
123+
"org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8",
124+
"",
125+
"# When configured, Gradle will fork up to org.gradle.workers.max JVMs to execute",
126+
"# projects in parallel. To learn more about parallel task execution, see the",
127+
"# section on Gradle build performance:",
128+
"# https://docs.gradle.org/current/userguide/performance.html#parallel_execution.",
129+
"# Default is `false`.",
130+
"#org.gradle.parallel=true",
131+
"",
132+
"# AndroidX package structure to make it clearer which packages are bundled with the",
133+
"# Android operating system, and which are packaged with your app's APK",
134+
"# https://developer.android.com/topic/libraries/support-library/androidx-rn",
135+
"android.useAndroidX=true",
136+
"# Automatically convert third-party libraries to use AndroidX",
137+
`${enableJetifier}android.enableJetifier=true`,
138+
"# Jetifier randomly fails on these libraries",
139+
`${enableJetifier}android.jetifier.ignorelist=hermes-android,react-android`,
140+
"",
141+
"# Use this property to specify which architecture you want to build.",
142+
"# You can also override it from the CLI using",
143+
"# ./gradlew <task> -PreactNativeArchitectures=x86_64",
144+
"reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64",
145+
"",
146+
"# Use this property to enable support to the new architecture.",
147+
"# This will allow you to use TurboModules and the Fabric render in",
148+
"# your application. You should enable this flag either if you want",
149+
"# to write custom TurboModules/Fabric components OR use libraries that",
150+
"# are providing them.",
151+
"# Note that this is incompatible with web debugging.",
152+
`${enableNewArch}newArchEnabled=true`,
153+
"#bridgelessEnabled=true",
154+
"",
155+
"# Uncomment the line below to build React Native from source.",
156+
"#react.buildFromSource=true",
157+
"",
158+
"# Version of Android NDK to build against.",
159+
"#ANDROID_NDK_VERSION=26.1.10909125",
160+
"",
161+
"# Version of Kotlin to build against.",
162+
"#KOTLIN_VERSION=1.8.22"
163+
);
164+
}
165+
99166
/**
100167
* @param {string} name Root project name
101-
* @param {string} prefix Platform prefix
168+
* @param {"" | "macos/" | "visionos/"} prefix Platform prefix
169+
* @param {number} targetVersion Target React Native version
102170
* @returns {string}
103171
*/
104-
export function podfile(name, prefix) {
172+
export function podfile(name, prefix, targetVersion) {
173+
// https://reactnative.dev/blog/2024/10/23/the-new-architecture-is-here
174+
/** @type {Record<typeof prefix, number>} */
175+
const newArchMatrix = {
176+
"": v(0, 76, 0),
177+
"macos/": v(1000, 0, 0),
178+
"visionos/": v(0, 76, 0),
179+
};
180+
const newArchEnabled = targetVersion >= newArchMatrix[prefix];
105181
return join(
106182
"ws_dir = Pathname.new(__dir__)",
107183
"ws_dir = ws_dir.parent until",
@@ -111,7 +187,7 @@ export function podfile(name, prefix) {
111187
"",
112188
`workspace '${name}.xcworkspace'`,
113189
"",
114-
`use_test_app! :hermes_enabled => true`,
190+
`use_test_app! :hermes_enabled => true, :fabric_enabled => ${newArchEnabled}`,
115191
""
116192
);
117193
}

test/configure/gatherConfig.test.ts

Lines changed: 116 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ describe("gatherConfig()", () => {
4242
it("returns configuration for all platforms", () => {
4343
deepEqual(gatherConfig(mockParams()), {
4444
dependencies: {
45-
"react-native-macos": "^0.73.0",
46-
"react-native-windows": "^0.73.0",
45+
"react-native-macos": "^0.76.0",
46+
"react-native-windows": "^0.76.0",
4747
},
4848
files: {
4949
".gitignore": {
@@ -98,9 +98,61 @@ describe("gatherConfig()", () => {
9898
"}",
9999
""
100100
),
101-
"android/gradle.properties": {
102-
source: "example/android/gradle.properties",
103-
},
101+
"android/gradle.properties": join(
102+
"# Project-wide Gradle settings.",
103+
"",
104+
"# IDE (e.g. Android Studio) users:",
105+
"# Gradle settings configured through the IDE *will override*",
106+
"# any settings specified in this file.",
107+
"",
108+
"# For more details on how to configure your build environment visit",
109+
"# http://www.gradle.org/docs/current/userguide/build_environment.html",
110+
"",
111+
"# Specifies the JVM arguments used for the Gradle Daemon. The setting is",
112+
"# particularly useful for configuring JVM memory settings for build performance.",
113+
"# This does not affect the JVM settings for the Gradle client VM.",
114+
"# The default is `-Xmx512m -XX:MaxMetaspaceSize=256m`.",
115+
"org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8",
116+
"",
117+
"# When configured, Gradle will fork up to org.gradle.workers.max JVMs to execute",
118+
"# projects in parallel. To learn more about parallel task execution, see the",
119+
"# section on Gradle build performance:",
120+
"# https://docs.gradle.org/current/userguide/performance.html#parallel_execution.",
121+
"# Default is `false`.",
122+
"#org.gradle.parallel=true",
123+
"",
124+
"# AndroidX package structure to make it clearer which packages are bundled with the",
125+
"# Android operating system, and which are packaged with your app's APK",
126+
"# https://developer.android.com/topic/libraries/support-library/androidx-rn",
127+
"android.useAndroidX=true",
128+
"# Automatically convert third-party libraries to use AndroidX",
129+
"#android.enableJetifier=true",
130+
"# Jetifier randomly fails on these libraries",
131+
"#android.jetifier.ignorelist=hermes-android,react-android",
132+
"",
133+
"# Use this property to specify which architecture you want to build.",
134+
"# You can also override it from the CLI using",
135+
"# ./gradlew <task> -PreactNativeArchitectures=x86_64",
136+
"reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64",
137+
"",
138+
"# Use this property to enable support to the new architecture.",
139+
"# This will allow you to use TurboModules and the Fabric render in",
140+
"# your application. You should enable this flag either if you want",
141+
"# to write custom TurboModules/Fabric components OR use libraries that",
142+
"# are providing them.",
143+
"# Note that this is incompatible with web debugging.",
144+
"newArchEnabled=true",
145+
"#bridgelessEnabled=true",
146+
"",
147+
"# Uncomment the line below to build React Native from source.",
148+
"#react.buildFromSource=true",
149+
"",
150+
"# Version of Android NDK to build against.",
151+
"#ANDROID_NDK_VERSION=26.1.10909125",
152+
"",
153+
"# Version of Kotlin to build against.",
154+
"#KOTLIN_VERSION=1.8.22"
155+
),
104156
"android/gradle/wrapper/gradle-wrapper.jar": {
105157
source: "example/android/gradle/wrapper/gradle-wrapper.jar",
106158
},
@@ -147,7 +199,7 @@ describe("gatherConfig()", () => {
147199
"",
148200
"workspace 'Test.xcworkspace'",
149201
"",
150-
"use_test_app! :hermes_enabled => true",
202+
"use_test_app! :hermes_enabled => true, :fabric_enabled => true",
151203
""
152204
),
153205
"macos/Podfile": join(
@@ -159,7 +211,7 @@ describe("gatherConfig()", () => {
159211
"",
160212
"workspace 'Test.xcworkspace'",
161213
"",
162-
"use_test_app! :hermes_enabled => true",
214+
"use_test_app! :hermes_enabled => true, :fabric_enabled => false",
163215
""
164216
),
165217
"metro.config.js": {
@@ -340,7 +392,7 @@ describe("gatherConfig()", () => {
340392
"",
341393
"workspace 'Test.xcworkspace'",
342394
"",
343-
"use_test_app! :hermes_enabled => true",
395+
"use_test_app! :hermes_enabled => true, :fabric_enabled => true",
344396
""
345397
),
346398
"metro.config.js": {
@@ -446,9 +498,61 @@ describe("gatherConfig()", () => {
446498
"}",
447499
""
448500
),
449-
"android/gradle.properties": {
450-
source: "example/android/gradle.properties",
451-
},
501+
"android/gradle.properties": join(
502+
"# Project-wide Gradle settings.",
503+
"",
504+
"# IDE (e.g. Android Studio) users:",
505+
"# Gradle settings configured through the IDE *will override*",
506+
"# any settings specified in this file.",
507+
"",
508+
"# For more details on how to configure your build environment visit",
509+
"# http://www.gradle.org/docs/current/userguide/build_environment.html",
510+
"",
511+
"# Specifies the JVM arguments used for the Gradle Daemon. The setting is",
512+
"# particularly useful for configuring JVM memory settings for build performance.",
513+
"# This does not affect the JVM settings for the Gradle client VM.",
514+
"# The default is `-Xmx512m -XX:MaxMetaspaceSize=256m`.",
515+
"org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8",
516+
"",
517+
"# When configured, Gradle will fork up to org.gradle.workers.max JVMs to execute",
518+
"# projects in parallel. To learn more about parallel task execution, see the",
519+
"# section on Gradle build performance:",
520+
"# https://docs.gradle.org/current/userguide/performance.html#parallel_execution.",
521+
"# Default is `false`.",
522+
"#org.gradle.parallel=true",
523+
"",
524+
"# AndroidX package structure to make it clearer which packages are bundled with the",
525+
"# Android operating system, and which are packaged with your app's APK",
526+
"# https://developer.android.com/topic/libraries/support-library/androidx-rn",
527+
"android.useAndroidX=true",
528+
"# Automatically convert third-party libraries to use AndroidX",
529+
"#android.enableJetifier=true",
530+
"# Jetifier randomly fails on these libraries",
531+
"#android.jetifier.ignorelist=hermes-android,react-android",
532+
"",
533+
"# Use this property to specify which architecture you want to build.",
534+
"# You can also override it from the CLI using",
535+
"# ./gradlew <task> -PreactNativeArchitectures=x86_64",
536+
"reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64",
537+
"",
538+
"# Use this property to enable support to the new architecture.",
539+
"# This will allow you to use TurboModules and the Fabric render in",
540+
"# your application. You should enable this flag either if you want",
541+
"# to write custom TurboModules/Fabric components OR use libraries that",
542+
"# are providing them.",
543+
"# Note that this is incompatible with web debugging.",
544+
"newArchEnabled=true",
545+
"#bridgelessEnabled=true",
546+
"",
547+
"# Uncomment the line below to build React Native from source.",
548+
"#react.buildFromSource=true",
549+
"",
550+
"# Version of Android NDK to build against.",
551+
"#ANDROID_NDK_VERSION=26.1.10909125",
552+
"",
553+
"# Version of Kotlin to build against.",
554+
"#KOTLIN_VERSION=1.8.22"
555+
),
452556
"android/gradle/wrapper/gradle-wrapper.jar": {
453557
source: "example/android/gradle/wrapper/gradle-wrapper.jar",
454558
},
@@ -495,7 +599,7 @@ describe("gatherConfig()", () => {
495599
"",
496600
"workspace 'Test.xcworkspace'",
497601
"",
498-
"use_test_app! :hermes_enabled => true",
602+
"use_test_app! :hermes_enabled => true, :fabric_enabled => true",
499603
""
500604
),
501605
"metro.config.js": {

test/configure/mockParams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function mockParams(
1111
name: "Test",
1212
packagePath: "test",
1313
testAppPath: ".",
14-
targetVersion: "^0.73.6",
14+
targetVersion: "0.76.8",
1515
platforms: ["android", "ios", "macos", "windows"],
1616
force: false,
1717
init: false,

0 commit comments

Comments
 (0)