@react-native/gradle-plugin 0.73.2 → 0.73.4
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
|
@@ -26,6 +26,10 @@ gradlePlugin {
|
|
|
26
26
|
id = "com.facebook.react"
|
|
27
27
|
implementationClass = "com.facebook.react.ReactPlugin"
|
|
28
28
|
}
|
|
29
|
+
create("reactrootproject") {
|
|
30
|
+
id = "com.facebook.react.rootproject"
|
|
31
|
+
implementationClass = "com.facebook.react.ReactRootProjectPlugin"
|
|
32
|
+
}
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
35
|
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ import com.facebook.react.tasks.GenerateCodegenSchemaTask
|
|
|
15
15
|
import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFieldsForApp
|
|
16
16
|
import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFieldsForLibraries
|
|
17
17
|
import com.facebook.react.utils.AgpConfiguratorUtils.configureDevPorts
|
|
18
|
+
import com.facebook.react.utils.AgpConfiguratorUtils.configureNamespaceForLibraries
|
|
18
19
|
import com.facebook.react.utils.BackwardCompatUtils.configureBackwardCompatibilityReactMap
|
|
19
20
|
import com.facebook.react.utils.DependencyUtils.configureDependencies
|
|
20
21
|
import com.facebook.react.utils.DependencyUtils.configureRepositories
|
|
@@ -80,6 +81,7 @@ class ReactPlugin : Plugin<Project> {
|
|
|
80
81
|
|
|
81
82
|
// Library Only Configuration
|
|
82
83
|
configureBuildConfigFieldsForLibraries(project)
|
|
84
|
+
configureNamespaceForLibraries(project)
|
|
83
85
|
project.pluginManager.withPlugin("com.android.library") {
|
|
84
86
|
configureCodegen(project, extension, rootExtension, isLibrary = true)
|
|
85
87
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
package com.facebook.react
|
|
9
|
+
|
|
10
|
+
import org.gradle.api.Plugin
|
|
11
|
+
import org.gradle.api.Project
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Gradle plugin applied to the `android/build.gradle` file.
|
|
15
|
+
*
|
|
16
|
+
* This plugin allows to specify project wide configurations that can be applied to both apps and
|
|
17
|
+
* libraries before they're evaluated.
|
|
18
|
+
*/
|
|
19
|
+
class ReactRootProjectPlugin : Plugin<Project> {
|
|
20
|
+
override fun apply(project: Project) {
|
|
21
|
+
project.subprojects {
|
|
22
|
+
// As the :app project (i.e. ReactPlugin) configures both namespaces and JVM toolchains
|
|
23
|
+
// for libraries, its evaluation must happen before the libraries' evaluation.
|
|
24
|
+
// Eventually the configuration of namespace/JVM toolchain can be moved inside this plugin.
|
|
25
|
+
if (it.path != ":app") {
|
|
26
|
+
it.evaluationDependsOn(":app")
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -8,12 +8,17 @@
|
|
|
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 {
|
|
@@ -63,6 +68,43 @@ internal object AgpConfiguratorUtils {
|
|
|
63
68
|
project.pluginManager.withPlugin("com.android.application", action)
|
|
64
69
|
project.pluginManager.withPlugin("com.android.library", action)
|
|
65
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
|
+
}
|
|
66
92
|
}
|
|
67
93
|
|
|
68
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
|
+
}
|