@@ -9,7 +9,6 @@ package com.facebook.react.utils
99
1010import com.android.build.api.variant.ApplicationAndroidComponentsExtension
1111import com.android.build.api.variant.LibraryAndroidComponentsExtension
12- import com.android.build.gradle.LibraryExtension
1312import com.facebook.react.ReactExtension
1413import com.facebook.react.utils.ProjectUtils.isEdgeToEdgeEnabled
1514import com.facebook.react.utils.ProjectUtils.isHermesEnabled
@@ -59,18 +58,21 @@ internal object AgpConfiguratorUtils {
5958 project.extensions
6059 .getByType(ApplicationAndroidComponentsExtension ::class .java)
6160 .finalizeDsl { ext ->
62- ext.buildFeatures.buildConfig = true
63- ext.defaultConfig.buildConfigField(" boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , " true" )
64- ext.defaultConfig.buildConfigField(
65- " boolean" ,
66- " IS_HERMES_ENABLED" ,
67- project.isHermesEnabled.toString(),
68- )
69- ext.defaultConfig.buildConfigField(
70- " boolean" ,
71- " IS_EDGE_TO_EDGE_ENABLED" ,
72- project.isEdgeToEdgeEnabled.toString(),
73- )
61+ ext.buildFeatures { buildConfig = true }
62+ // In AGP 9.1, buildConfigField is accessed via defaultConfig
63+ ext.defaultConfig {
64+ buildConfigField(" boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , " true" )
65+ buildConfigField(
66+ " boolean" ,
67+ " IS_HERMES_ENABLED" ,
68+ project.isHermesEnabled.toString(),
69+ )
70+ buildConfigField(
71+ " boolean" ,
72+ " IS_EDGE_TO_EDGE_ENABLED" ,
73+ project.isEdgeToEdgeEnabled.toString(),
74+ )
75+ }
7476 }
7577 }
7678 project.pluginManager.withPlugin(" com.android.application" , action)
@@ -82,7 +84,7 @@ internal object AgpConfiguratorUtils {
8284 subproject.pluginManager.withPlugin(" com.android.library" ) {
8385 subproject.extensions
8486 .getByType(LibraryAndroidComponentsExtension ::class .java)
85- .finalizeDsl { ext -> ext.buildFeatures. buildConfig = true }
87+ .finalizeDsl { ext -> ext.buildFeatures { buildConfig = true } }
8688 }
8789 }
8890 }
@@ -97,13 +99,16 @@ internal object AgpConfiguratorUtils {
9799 project.extensions
98100 .getByType(ApplicationAndroidComponentsExtension ::class .java)
99101 .finalizeDsl { ext ->
100- ext.buildFeatures.resValues = true
101- ext.defaultConfig.resValue(
102- " string" ,
103- " react_native_dev_server_ip" ,
104- devServerIp,
105- )
106- ext.defaultConfig.resValue(" integer" , " react_native_dev_server_port" , devServerPort)
102+ ext.buildFeatures { resValues = true }
103+ // In AGP 9.1, resValue is accessed via defaultConfig
104+ ext.defaultConfig {
105+ resValue(
106+ " string" ,
107+ " react_native_dev_server_ip" ,
108+ devServerIp,
109+ )
110+ resValue(" integer" , " react_native_dev_server_port" , devServerPort)
111+ }
107112 }
108113 }
109114
@@ -114,22 +119,22 @@ internal object AgpConfiguratorUtils {
114119 fun configureNamespaceForLibraries (appProject : Project ) {
115120 appProject.rootProject.allprojects { subproject ->
116121 subproject.pluginManager.withPlugin(" com.android.library" ) {
117- subproject.extensions
122+ val components = subproject.extensions
118123 .getByType(LibraryAndroidComponentsExtension ::class .java)
119- .finalizeDsl { ext ->
120- if (ext.namespace == null ) {
121- val android = subproject.extensions.getByType( LibraryExtension :: class .java)
122- val manifestFile = android.sourceSets.getByName( " main" ).manifest.srcFile
123-
124- manifestFile
125- .takeIf { it.exists() }
126- ?.let { file ->
127- getPackageNameFromManifest(file)?.let { packageName ->
128- ext .namespace = packageName
129- }
130- }
131- }
132- }
124+
125+ components.finalizeDsl { dsl ->
126+ if (dsl.namespace.isNullOrEmpty()) {
127+ val manifestFile = subproject.file( " src/ main/AndroidManifest.xml " )
128+
129+ manifestFile
130+ .takeIf { it.exists() }
131+ ?.let { file ->
132+ getPackageNameFromManifest(file)?.let { packageName ->
133+ dsl .namespace = packageName
134+ }
135+ }
136+ }
137+ }
133138 }
134139 }
135140 }
0 commit comments