Skip to content

Commit 9757796

Browse files
committed
android
1 parent c350c3a commit 9757796

File tree

3 files changed

+179
-14
lines changed

3 files changed

+179
-14
lines changed

scripts/configure.mjs

Lines changed: 2 additions & 8 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,
@@ -353,14 +354,7 @@ export const getConfig = (() => {
353354
}
354355
return props;
355356
})(),
356-
"gradle.properties": {
357-
source: path.join(
358-
testAppPath,
359-
"example",
360-
"android",
361-
"gradle.properties"
362-
),
363-
},
357+
"gradle.properties": gradleProperties(targetVersionNum),
364358
gradlew: {
365359
source: path.join(testAppPath, "example", "android", "gradlew"),
366360
},

scripts/template.mjs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,80 @@ export function buildGradle() {
9797
);
9898
}
9999

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+
100166
/**
101167
* @param {string} name Root project name
102168
* @param {"" | "macos/" | "visionos/"} prefix Platform prefix
103169
* @param {number} targetVersion Target React Native version
104170
* @returns {string}
105171
*/
106172
export function podfile(name, prefix, targetVersion) {
173+
// https://reactnative.dev/blog/2024/10/23/the-new-architecture-is-here
107174
/** @type {Record<typeof prefix, number>} */
108175
const newArchMatrix = {
109176
"": v(0, 76, 0),

test/configure/gatherConfig.test.ts

Lines changed: 110 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
},
@@ -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
},

0 commit comments

Comments
 (0)