@react-native/gradle-plugin 0.73.1 → 0.73.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build.gradle.kts
CHANGED
package/package.json
CHANGED
|
@@ -12,8 +12,10 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn
|
|
|
12
12
|
import com.facebook.react.internal.PrivateReactExtension
|
|
13
13
|
import com.facebook.react.tasks.GenerateCodegenArtifactsTask
|
|
14
14
|
import com.facebook.react.tasks.GenerateCodegenSchemaTask
|
|
15
|
-
import com.facebook.react.utils.AgpConfiguratorUtils.
|
|
15
|
+
import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFieldsForApp
|
|
16
|
+
import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFieldsForLibraries
|
|
16
17
|
import com.facebook.react.utils.AgpConfiguratorUtils.configureDevPorts
|
|
18
|
+
import com.facebook.react.utils.AgpConfiguratorUtils.configureNamespaceForLibraries
|
|
17
19
|
import com.facebook.react.utils.BackwardCompatUtils.configureBackwardCompatibilityReactMap
|
|
18
20
|
import com.facebook.react.utils.DependencyUtils.configureDependencies
|
|
19
21
|
import com.facebook.react.utils.DependencyUtils.configureRepositories
|
|
@@ -64,9 +66,10 @@ class ReactPlugin : Plugin<Project> {
|
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
configureReactNativeNdk(project, extension)
|
|
67
|
-
|
|
69
|
+
configureBuildConfigFieldsForApp(project, extension)
|
|
68
70
|
configureDevPorts(project)
|
|
69
71
|
configureBackwardCompatibilityReactMap(project)
|
|
72
|
+
configureJavaToolChains(project)
|
|
70
73
|
|
|
71
74
|
project.extensions.getByType(AndroidComponentsExtension::class.java).apply {
|
|
72
75
|
onVariants(selector().all()) { variant ->
|
|
@@ -77,12 +80,11 @@ class ReactPlugin : Plugin<Project> {
|
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
// Library Only Configuration
|
|
83
|
+
configureBuildConfigFieldsForLibraries(project)
|
|
84
|
+
configureNamespaceForLibraries(project)
|
|
80
85
|
project.pluginManager.withPlugin("com.android.library") {
|
|
81
86
|
configureCodegen(project, extension, rootExtension, isLibrary = true)
|
|
82
87
|
}
|
|
83
|
-
|
|
84
|
-
// Library and App Configurations
|
|
85
|
-
configureJavaToolChains(project)
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
private fun checkJvmVersion(project: Project) {
|
|
@@ -23,6 +23,7 @@ internal fun Project.configureReactTasks(variant: Variant, config: ReactExtensio
|
|
|
23
23
|
val targetName = variant.name.capitalizeCompat()
|
|
24
24
|
val targetPath = variant.name
|
|
25
25
|
|
|
26
|
+
val buildDir = this.layout.buildDirectory.get().asFile
|
|
26
27
|
// Resources: generated/assets/react/<variant>/index.android.bundle
|
|
27
28
|
val resourcesDir = File(buildDir, "generated/res/react/$targetPath")
|
|
28
29
|
// Bundle: generated/assets/react/<variant>/index.android.bundle
|
|
@@ -8,17 +8,22 @@
|
|
|
8
8
|
package com.facebook.react.utils
|
|
9
9
|
|
|
10
10
|
import com.android.build.api.variant.AndroidComponentsExtension
|
|
11
|
+
import com.android.build.gradle.LibraryExtension
|
|
11
12
|
import com.facebook.react.ReactExtension
|
|
12
13
|
import com.facebook.react.utils.ProjectUtils.isHermesEnabled
|
|
13
14
|
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
|
|
15
|
+
import java.io.File
|
|
16
|
+
import javax.xml.parsers.DocumentBuilder
|
|
17
|
+
import javax.xml.parsers.DocumentBuilderFactory
|
|
14
18
|
import org.gradle.api.Action
|
|
15
19
|
import org.gradle.api.Project
|
|
16
20
|
import org.gradle.api.plugins.AppliedPlugin
|
|
21
|
+
import org.w3c.dom.Element
|
|
17
22
|
|
|
18
23
|
@Suppress("UnstableApiUsage")
|
|
19
24
|
internal object AgpConfiguratorUtils {
|
|
20
25
|
|
|
21
|
-
fun
|
|
26
|
+
fun configureBuildConfigFieldsForApp(project: Project, extension: ReactExtension) {
|
|
22
27
|
val action =
|
|
23
28
|
Action<AppliedPlugin> {
|
|
24
29
|
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
|
|
@@ -35,6 +40,16 @@ internal object AgpConfiguratorUtils {
|
|
|
35
40
|
project.pluginManager.withPlugin("com.android.library", action)
|
|
36
41
|
}
|
|
37
42
|
|
|
43
|
+
fun configureBuildConfigFieldsForLibraries(appProject: Project) {
|
|
44
|
+
appProject.rootProject.allprojects { subproject ->
|
|
45
|
+
subproject.pluginManager.withPlugin("com.android.library") {
|
|
46
|
+
subproject.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
|
|
47
|
+
ext.buildFeatures.buildConfig = true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
fun configureDevPorts(project: Project) {
|
|
39
54
|
val devServerPort =
|
|
40
55
|
project.properties["reactNativeDevServerPort"]?.toString() ?: DEFAULT_DEV_SERVER_PORT
|
|
@@ -53,6 +68,43 @@ internal object AgpConfiguratorUtils {
|
|
|
53
68
|
project.pluginManager.withPlugin("com.android.application", action)
|
|
54
69
|
project.pluginManager.withPlugin("com.android.library", action)
|
|
55
70
|
}
|
|
71
|
+
|
|
72
|
+
fun configureNamespaceForLibraries(appProject: Project) {
|
|
73
|
+
appProject.rootProject.allprojects { subproject ->
|
|
74
|
+
subproject.pluginManager.withPlugin("com.android.library") {
|
|
75
|
+
subproject.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
|
|
76
|
+
if (ext.namespace == null) {
|
|
77
|
+
val android = subproject.extensions.getByType(LibraryExtension::class.java)
|
|
78
|
+
val manifestFile = android.sourceSets.getByName("main").manifest.srcFile
|
|
79
|
+
|
|
80
|
+
manifestFile
|
|
81
|
+
.takeIf { it.exists() }
|
|
82
|
+
?.let { file ->
|
|
83
|
+
getPackageNameFromManifest(file)?.let { packageName ->
|
|
84
|
+
ext.namespace = packageName
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
56
92
|
}
|
|
57
93
|
|
|
58
94
|
const val DEFAULT_DEV_SERVER_PORT = "8081"
|
|
95
|
+
|
|
96
|
+
fun getPackageNameFromManifest(manifest: File): String? {
|
|
97
|
+
val factory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()
|
|
98
|
+
val builder: DocumentBuilder = factory.newDocumentBuilder()
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
val xmlDocument = builder.parse(manifest)
|
|
102
|
+
|
|
103
|
+
val manifestElement = xmlDocument.getElementsByTagName("manifest").item(0) as? Element
|
|
104
|
+
val packageName = manifestElement?.getAttribute("package")
|
|
105
|
+
|
|
106
|
+
return if (packageName.isNullOrEmpty()) null else packageName
|
|
107
|
+
} catch (e: Exception) {
|
|
108
|
+
return null
|
|
109
|
+
}
|
|
110
|
+
}
|