@ohos-ports/react-native-gradle-plugin 0.71.19-beta.0 → 0.86.0-beta.0
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/README.md +11 -4
- package/build.gradle.kts +33 -41
- package/gradle/libs.versions.toml +22 -0
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +3 -1
- package/gradle.properties +2 -0
- package/gradlew +32 -18
- package/gradlew.bat +22 -18
- package/package.json +21 -11
- package/react-native-gradle-plugin/README.md +17 -0
- package/react-native-gradle-plugin/build.gradle.kts +83 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactExtension.kt +78 -10
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +320 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactRootProjectPlugin.kt +86 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/TaskConfiguration.kt +36 -25
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt +11 -4
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt +60 -50
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateAutolinkingNewArchitecturesFileTask.kt +252 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt +8 -3
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt +11 -18
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateEntryPointTask.kt +108 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GeneratePackageListTask.kt +214 -0
- package/{src/main/kotlin/com/facebook/react/tasks → react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal}/BuildCodegenCLITask.kt +24 -17
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/CustomExecTask.kt +46 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareBoostTask.kt +10 -4
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/PrepareGflagsTask.kt +119 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareGlogTask.kt +26 -18
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PreparePrefabHeadersTask.kt +28 -12
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/utils/PrefabPreprocessingEntry.kt +4 -3
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +163 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt +71 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +299 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt +64 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt +59 -65
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/PathUtils.kt +44 -30
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +119 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PropertyUtils.kt +96 -0
- package/settings-plugin/build.gradle.kts +73 -0
- package/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt +217 -0
- package/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsPlugin.kt +23 -0
- package/settings-plugin/src/test/kotlin/com/facebook/react/ReactSettingsExtensionTest.kt +475 -0
- package/settings.gradle.kts +10 -1
- package/shared/build.gradle.kts +52 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingAndroidProjectJson.kt +18 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingConfigJson.kt +14 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesJson.kt +18 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesPlatformAndroidJson.kt +23 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesPlatformJson.kt +12 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingProjectJson.kt +10 -0
- package/{src → shared/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfig.kt +2 -1
- package/{src → shared/src}/main/kotlin/com/facebook/react/model/ModelPackageJson.kt +1 -1
- package/shared/src/main/kotlin/com/facebook/react/utils/JsonUtils.kt +43 -0
- package/shared/src/main/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtils.kt +32 -0
- package/{src → shared/src}/main/kotlin/com/facebook/react/utils/Os.kt +7 -6
- package/{src → shared/src}/main/kotlin/com/facebook/react/utils/TaskUtils.kt +4 -5
- package/shared/src/test/kotlin/com/facebook/react/utils/JsonUtilsTest.kt +382 -0
- package/shared/src/test/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtilsTest.kt +82 -0
- package/shared/src/test/kotlin/com/facebook/react/utils/OsTest.kt +87 -0
- package/shared/src/test/kotlin/com/facebook/react/utils/TaskUtilsTest.kt +76 -0
- package/shared-testutil/build.gradle.kts +46 -0
- package/shared-testutil/src/main/kotlin/com/facebook/react/tests/OsRule.kt +52 -0
- package/shared-testutil/src/main/kotlin/com/facebook/react/tests/WithOs.kt +17 -0
- package/build/libs/react-native-gradle-plugin.jar +0 -0
- package/index.js +0 -73
- package/src/main/kotlin/com/facebook/react/ReactPlugin.kt +0 -212
- package/src/main/kotlin/com/facebook/react/tasks/internal/PrepareJSCTask.kt +0 -50
- package/src/main/kotlin/com/facebook/react/tasks/internal/PrepareLibeventTask.kt +0 -51
- package/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +0 -54
- package/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt +0 -48
- package/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +0 -109
- package/src/main/kotlin/com/facebook/react/utils/JsonUtils.kt +0 -21
- package/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +0 -55
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/FileUtils.kt +0 -0
- /package/{src → shared/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfigAndroid.kt +0 -0
package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
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.utils
|
|
9
|
+
|
|
10
|
+
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
|
|
11
|
+
import com.android.build.api.variant.LibraryAndroidComponentsExtension
|
|
12
|
+
import com.android.build.gradle.LibraryExtension
|
|
13
|
+
import com.facebook.react.ReactExtension
|
|
14
|
+
import com.facebook.react.utils.ProjectUtils.isEdgeToEdgeEnabled
|
|
15
|
+
import com.facebook.react.utils.ProjectUtils.isHermesEnabled
|
|
16
|
+
import java.io.File
|
|
17
|
+
import java.net.Inet4Address
|
|
18
|
+
import java.net.NetworkInterface
|
|
19
|
+
import javax.xml.parsers.DocumentBuilder
|
|
20
|
+
import javax.xml.parsers.DocumentBuilderFactory
|
|
21
|
+
import kotlin.plus
|
|
22
|
+
import org.gradle.api.Action
|
|
23
|
+
import org.gradle.api.Project
|
|
24
|
+
import org.gradle.api.plugins.AppliedPlugin
|
|
25
|
+
import org.w3c.dom.Element
|
|
26
|
+
|
|
27
|
+
@Suppress("UnstableApiUsage")
|
|
28
|
+
internal object AgpConfiguratorUtils {
|
|
29
|
+
|
|
30
|
+
fun configureBuildTypesForApp(project: Project) {
|
|
31
|
+
val action =
|
|
32
|
+
Action<AppliedPlugin> {
|
|
33
|
+
project.extensions
|
|
34
|
+
.getByType(ApplicationAndroidComponentsExtension::class.java)
|
|
35
|
+
.finalizeDsl { ext ->
|
|
36
|
+
ext.buildTypes {
|
|
37
|
+
val debug =
|
|
38
|
+
getByName("debug").apply {
|
|
39
|
+
manifestPlaceholders["usesCleartextTraffic"] = "true"
|
|
40
|
+
}
|
|
41
|
+
getByName("release").apply {
|
|
42
|
+
manifestPlaceholders["usesCleartextTraffic"] = "false"
|
|
43
|
+
}
|
|
44
|
+
maybeCreate("debugOptimized").apply {
|
|
45
|
+
manifestPlaceholders["usesCleartextTraffic"] = "true"
|
|
46
|
+
initWith(debug)
|
|
47
|
+
matchingFallbacks += listOf("release")
|
|
48
|
+
externalNativeBuild { cmake { arguments("-DCMAKE_BUILD_TYPE=Release") } }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
project.pluginManager.withPlugin("com.android.application", action)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fun configureBuildConfigFieldsForApp(project: Project, extension: ReactExtension) {
|
|
57
|
+
val action =
|
|
58
|
+
Action<AppliedPlugin> {
|
|
59
|
+
project.extensions
|
|
60
|
+
.getByType(ApplicationAndroidComponentsExtension::class.java)
|
|
61
|
+
.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
|
+
)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
project.pluginManager.withPlugin("com.android.application", action)
|
|
77
|
+
project.pluginManager.withPlugin("com.android.library", action)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fun configureBuildConfigFieldsForLibraries(appProject: Project) {
|
|
81
|
+
appProject.rootProject.allprojects { subproject ->
|
|
82
|
+
subproject.pluginManager.withPlugin("com.android.library") {
|
|
83
|
+
subproject.extensions
|
|
84
|
+
.getByType(LibraryAndroidComponentsExtension::class.java)
|
|
85
|
+
.finalizeDsl { ext -> ext.buildFeatures.buildConfig = true }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
fun configureDevServerLocation(project: Project) {
|
|
91
|
+
val devServerIp = project.properties["reactNativeDevServerIp"]?.toString() ?: getHostIpAddress()
|
|
92
|
+
val devServerPort =
|
|
93
|
+
project.properties["reactNativeDevServerPort"]?.toString() ?: DEFAULT_DEV_SERVER_PORT
|
|
94
|
+
|
|
95
|
+
val action =
|
|
96
|
+
Action<AppliedPlugin> {
|
|
97
|
+
project.extensions
|
|
98
|
+
.getByType(ApplicationAndroidComponentsExtension::class.java)
|
|
99
|
+
.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)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
project.pluginManager.withPlugin("com.android.application", action)
|
|
111
|
+
project.pluginManager.withPlugin("com.android.library", action)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
fun configureNamespaceForLibraries(appProject: Project) {
|
|
115
|
+
appProject.rootProject.allprojects { subproject ->
|
|
116
|
+
subproject.pluginManager.withPlugin("com.android.library") {
|
|
117
|
+
subproject.extensions
|
|
118
|
+
.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
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const val DEFAULT_DEV_SERVER_PORT = "8081"
|
|
139
|
+
|
|
140
|
+
fun getPackageNameFromManifest(manifest: File): String? {
|
|
141
|
+
val factory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()
|
|
142
|
+
val builder: DocumentBuilder = factory.newDocumentBuilder()
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
val xmlDocument = builder.parse(manifest)
|
|
146
|
+
|
|
147
|
+
val manifestElement = xmlDocument.getElementsByTagName("manifest").item(0) as? Element
|
|
148
|
+
val packageName = manifestElement?.getAttribute("package")
|
|
149
|
+
|
|
150
|
+
return if (packageName.isNullOrEmpty()) null else packageName
|
|
151
|
+
} catch (e: Exception) {
|
|
152
|
+
return null
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
internal fun getHostIpAddress(): String =
|
|
157
|
+
NetworkInterface.getNetworkInterfaces()
|
|
158
|
+
.asSequence()
|
|
159
|
+
.filter { it.isUp && !it.isLoopback }
|
|
160
|
+
.flatMap { it.inetAddresses.asSequence() }
|
|
161
|
+
.filter { it is Inet4Address && !it.isLoopbackAddress }
|
|
162
|
+
.map { it.hostAddress }
|
|
163
|
+
.firstOrNull() ?: "localhost"
|
package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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.utils
|
|
9
|
+
|
|
10
|
+
import java.util.*
|
|
11
|
+
import org.gradle.api.Project
|
|
12
|
+
|
|
13
|
+
internal object BackwardCompatUtils {
|
|
14
|
+
private var hasShownJSCRemovalMessage = false
|
|
15
|
+
|
|
16
|
+
fun configureBackwardCompatibilityReactMap(project: Project) {
|
|
17
|
+
if (project.extensions.extraProperties.has("react")) {
|
|
18
|
+
@Suppress("UNCHECKED_CAST")
|
|
19
|
+
val reactMap =
|
|
20
|
+
project.extensions.extraProperties.get("react") as? Map<String, Any?> ?: mapOf()
|
|
21
|
+
if (reactMap.isNotEmpty()) {
|
|
22
|
+
project.logger.error(
|
|
23
|
+
"""
|
|
24
|
+
********************************************************************************
|
|
25
|
+
|
|
26
|
+
ERROR: Using old project.ext.react configuration.
|
|
27
|
+
We identified that your project is using a old configuration block as:
|
|
28
|
+
|
|
29
|
+
project.ext.react = [
|
|
30
|
+
// ...
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
You should migrate to the new configuration:
|
|
34
|
+
|
|
35
|
+
react {
|
|
36
|
+
// ...
|
|
37
|
+
}
|
|
38
|
+
You can find documentation inside `android/app/build.gradle` on how to use it.
|
|
39
|
+
|
|
40
|
+
********************************************************************************
|
|
41
|
+
"""
|
|
42
|
+
.trimIndent()
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// We set an empty react[] map so if a library is reading it, they will find empty values.
|
|
48
|
+
project.extensions.extraProperties.set("react", mapOf<String, String>())
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fun showJSCRemovalMessage(project: Project) {
|
|
52
|
+
if (hasShownJSCRemovalMessage) {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
val message =
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
=============== JavaScriptCore is being moved ===============
|
|
60
|
+
JavaScriptCore has been extracted from react-native core
|
|
61
|
+
and will be removed in a future release. It can now be
|
|
62
|
+
installed from `@react-native-community/javascriptcore`
|
|
63
|
+
See: https://github.com/react-native-community/javascriptcore
|
|
64
|
+
=============================================================
|
|
65
|
+
|
|
66
|
+
"""
|
|
67
|
+
.trimIndent()
|
|
68
|
+
project.logger.warn(message)
|
|
69
|
+
hasShownJSCRemovalMessage = true
|
|
70
|
+
}
|
|
71
|
+
}
|
package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
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.utils
|
|
9
|
+
|
|
10
|
+
import com.facebook.react.utils.PropertyUtils.DEFAULT_INTERNAL_HERMES_PUBLISHING_GROUP
|
|
11
|
+
import com.facebook.react.utils.PropertyUtils.DEFAULT_INTERNAL_REACT_PUBLISHING_GROUP
|
|
12
|
+
import com.facebook.react.utils.PropertyUtils.EXCLUSIVE_ENTEPRISE_REPOSITORY
|
|
13
|
+
import com.facebook.react.utils.PropertyUtils.INCLUDE_JITPACK_REPOSITORY
|
|
14
|
+
import com.facebook.react.utils.PropertyUtils.INCLUDE_JITPACK_REPOSITORY_DEFAULT
|
|
15
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_HERMES_PUBLISHING_GROUP
|
|
16
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_HERMES_V1_VERSION_NAME
|
|
17
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_HERMES_VERSION_NAME
|
|
18
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO
|
|
19
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_REACT_PUBLISHING_GROUP
|
|
20
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_USE_HERMES_NIGHTLY
|
|
21
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_VERSION_NAME
|
|
22
|
+
import com.facebook.react.utils.PropertyUtils.SCOPED_EXCLUSIVE_ENTEPRISE_REPOSITORY
|
|
23
|
+
import com.facebook.react.utils.PropertyUtils.SCOPED_INCLUDE_JITPACK_REPOSITORY
|
|
24
|
+
import java.io.File
|
|
25
|
+
import java.net.URI
|
|
26
|
+
import java.util.*
|
|
27
|
+
import org.gradle.api.Project
|
|
28
|
+
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
|
|
29
|
+
|
|
30
|
+
internal object DependencyUtils {
|
|
31
|
+
|
|
32
|
+
internal data class Coordinates(
|
|
33
|
+
val versionString: String,
|
|
34
|
+
val hermesVersionString: String,
|
|
35
|
+
val hermesV1VersionString: String,
|
|
36
|
+
val reactGroupString: String = DEFAULT_INTERNAL_REACT_PUBLISHING_GROUP,
|
|
37
|
+
val hermesGroupString: String = DEFAULT_INTERNAL_HERMES_PUBLISHING_GROUP,
|
|
38
|
+
private val isHermesNightly: Boolean = false,
|
|
39
|
+
) {
|
|
40
|
+
val isNightly: Boolean
|
|
41
|
+
get() = versionString.isNightly() || isHermesNightly
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* This method takes care of configuring the repositories{} block for both the app and all the 3rd
|
|
46
|
+
* party libraries which are auto-linked.
|
|
47
|
+
*/
|
|
48
|
+
fun configureRepositories(project: Project, isNightly: Boolean) {
|
|
49
|
+
val exclusiveEnterpriseRepository = project.rootProject.exclusiveEnterpriseRepository()
|
|
50
|
+
if (exclusiveEnterpriseRepository != null) {
|
|
51
|
+
project.logger.lifecycle(
|
|
52
|
+
"Replacing ALL Maven Repositories with: $exclusiveEnterpriseRepository"
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
project.rootProject.allprojects { eachProject ->
|
|
57
|
+
with(eachProject) {
|
|
58
|
+
if (hasProperty(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO)) {
|
|
59
|
+
val mavenLocalRepoPath = property(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO) as String
|
|
60
|
+
mavenRepoFromURI(File(mavenLocalRepoPath).toURI()) { repo ->
|
|
61
|
+
repo.content { it.excludeGroup("org.webkit") }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (exclusiveEnterpriseRepository != null) {
|
|
66
|
+
// We remove all previously set repositories and only configure the proxy provided by the
|
|
67
|
+
// user.
|
|
68
|
+
rootProject.repositories.clear()
|
|
69
|
+
mavenRepoFromUrl(exclusiveEnterpriseRepository)
|
|
70
|
+
// We return here as we don't want to configure other repositories as well.
|
|
71
|
+
return@allprojects
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (isNightly) {
|
|
75
|
+
// We add the snapshot for users on nightlies.
|
|
76
|
+
mavenRepoFromUrl("https://central.sonatype.com/repository/maven-snapshots/") { repo ->
|
|
77
|
+
repo.content { it.excludeGroup("org.webkit") }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
repositories.mavenCentral { repo ->
|
|
81
|
+
// We don't want to fetch JSC from Maven Central as there are older versions there.
|
|
82
|
+
repo.content { it.excludeGroup("org.webkit") }
|
|
83
|
+
|
|
84
|
+
// If the user provided a react.internal.mavenLocalRepo, do not attempt to load
|
|
85
|
+
// anything from Maven Central that is react related.
|
|
86
|
+
if (hasProperty(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO)) {
|
|
87
|
+
repo.content { it.excludeGroup("com.facebook.react") }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
repositories.google { repo ->
|
|
91
|
+
repo.content {
|
|
92
|
+
// We don't want to fetch JSC or React from Google
|
|
93
|
+
it.excludeGroup("org.webkit")
|
|
94
|
+
it.excludeGroup("io.github.react-native-community")
|
|
95
|
+
it.excludeGroup("com.facebook.react")
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (shouldAddJitPack()) {
|
|
99
|
+
mavenRepoFromUrl("https://www.jitpack.io") { repo ->
|
|
100
|
+
repo.content { content ->
|
|
101
|
+
// We don't want to fetch JSC or React from JitPack
|
|
102
|
+
content.excludeGroup("org.webkit")
|
|
103
|
+
content.excludeGroup("io.github.react-native-community")
|
|
104
|
+
content.excludeGroup("com.facebook.react")
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* This method takes care of configuring the resolution strategy for both the app and all the 3rd
|
|
114
|
+
* party libraries which are auto-linked. Specifically it takes care of:
|
|
115
|
+
* - Forcing the react-android/hermes-android version to the one specified in the package.json
|
|
116
|
+
* - Substituting `react-native` with `react-android` and `hermes-engine` with `hermes-android`
|
|
117
|
+
* - Selecting between the classic Hermes and Hermes V1
|
|
118
|
+
*/
|
|
119
|
+
fun configureDependencies(
|
|
120
|
+
project: Project,
|
|
121
|
+
coordinates: Coordinates,
|
|
122
|
+
hermesV1Enabled: Boolean = true,
|
|
123
|
+
) {
|
|
124
|
+
if (
|
|
125
|
+
coordinates.versionString.isBlank() ||
|
|
126
|
+
(!hermesV1Enabled && coordinates.hermesVersionString.isBlank()) ||
|
|
127
|
+
(hermesV1Enabled && coordinates.hermesV1VersionString.isBlank())
|
|
128
|
+
)
|
|
129
|
+
return
|
|
130
|
+
project.rootProject.allprojects { eachProject ->
|
|
131
|
+
eachProject.configurations.all { configuration ->
|
|
132
|
+
// Here we set a dependencySubstitution for both react-native and hermes-engine as those
|
|
133
|
+
// coordinates are voided due to https://github.com/facebook/react-native/issues/35210
|
|
134
|
+
// This allows users to import libraries that are still using
|
|
135
|
+
// implementation("com.facebook.react:react-native:+") and resolve the right dependency.
|
|
136
|
+
configuration.resolutionStrategy.dependencySubstitution {
|
|
137
|
+
getDependencySubstitutions(coordinates, hermesV1Enabled).forEach { (module, dest, reason)
|
|
138
|
+
->
|
|
139
|
+
it.substitute(it.module(module)).using(it.module(dest)).because(reason)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
configuration.resolutionStrategy.force(
|
|
143
|
+
"${coordinates.reactGroupString}:react-android:${coordinates.versionString}",
|
|
144
|
+
)
|
|
145
|
+
if (!(eachProject.findProperty(INTERNAL_USE_HERMES_NIGHTLY) as? String).toBoolean()) {
|
|
146
|
+
// Contributors only: The hermes-engine version is forced only if the user has
|
|
147
|
+
// not opted into using nightlies for local development.
|
|
148
|
+
configuration.resolutionStrategy.force(
|
|
149
|
+
"${coordinates.hermesGroupString}:hermes-android:${if (hermesV1Enabled) coordinates.hermesV1VersionString else coordinates.hermesVersionString}"
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
internal fun getDependencySubstitutions(
|
|
157
|
+
coordinates: Coordinates,
|
|
158
|
+
hermesV1Enabled: Boolean = true,
|
|
159
|
+
): List<Triple<String, String, String>> {
|
|
160
|
+
val dependencySubstitution = mutableListOf<Triple<String, String, String>>()
|
|
161
|
+
val hermesVersion =
|
|
162
|
+
if (hermesV1Enabled) coordinates.hermesV1VersionString else coordinates.hermesVersionString
|
|
163
|
+
val hermesVersionString = "${coordinates.hermesGroupString}:hermes-android:${hermesVersion}"
|
|
164
|
+
dependencySubstitution.add(
|
|
165
|
+
Triple(
|
|
166
|
+
"com.facebook.react:react-native",
|
|
167
|
+
"${coordinates.reactGroupString}:react-android:${coordinates.versionString}",
|
|
168
|
+
"The react-native artifact was deprecated in favor of react-android due to https://github.com/facebook/react-native/issues/35210.",
|
|
169
|
+
)
|
|
170
|
+
)
|
|
171
|
+
dependencySubstitution.add(
|
|
172
|
+
Triple(
|
|
173
|
+
"com.facebook.react:hermes-engine",
|
|
174
|
+
hermesVersionString,
|
|
175
|
+
"The hermes-engine artifact was deprecated in favor of hermes-android due to https://github.com/facebook/react-native/issues/35210.",
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
dependencySubstitution.add(
|
|
179
|
+
Triple(
|
|
180
|
+
"com.facebook.react:hermes-android",
|
|
181
|
+
hermesVersionString,
|
|
182
|
+
"The hermes-android artifact was moved to com.facebook.hermes publishing group.",
|
|
183
|
+
)
|
|
184
|
+
)
|
|
185
|
+
if (coordinates.reactGroupString != DEFAULT_INTERNAL_REACT_PUBLISHING_GROUP) {
|
|
186
|
+
dependencySubstitution.add(
|
|
187
|
+
Triple(
|
|
188
|
+
"com.facebook.react:react-android",
|
|
189
|
+
"${coordinates.reactGroupString}:react-android:${coordinates.versionString}",
|
|
190
|
+
"The react-android dependency was modified to use the correct Maven group.",
|
|
191
|
+
)
|
|
192
|
+
)
|
|
193
|
+
dependencySubstitution.add(
|
|
194
|
+
Triple(
|
|
195
|
+
"com.facebook.react:hermes-android",
|
|
196
|
+
hermesVersionString,
|
|
197
|
+
"The hermes-android dependency was modified to use the correct Maven group.",
|
|
198
|
+
)
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
if (coordinates.hermesGroupString != DEFAULT_INTERNAL_HERMES_PUBLISHING_GROUP) {
|
|
202
|
+
dependencySubstitution.add(
|
|
203
|
+
Triple(
|
|
204
|
+
"com.facebook.hermes:hermes-android",
|
|
205
|
+
hermesVersionString,
|
|
206
|
+
"The hermes-android dependency was modified to use the correct Maven group.",
|
|
207
|
+
)
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
return dependencySubstitution
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
fun readVersionAndGroupStrings(
|
|
214
|
+
project: Project,
|
|
215
|
+
propertiesFile: File,
|
|
216
|
+
hermesVersionFile: File,
|
|
217
|
+
): Coordinates {
|
|
218
|
+
val reactAndroidProperties = Properties()
|
|
219
|
+
propertiesFile.inputStream().use { reactAndroidProperties.load(it) }
|
|
220
|
+
val versionStringFromFile = (reactAndroidProperties[INTERNAL_VERSION_NAME] as? String).orEmpty()
|
|
221
|
+
// If on a nightly, we need to fetch the -SNAPSHOT artifact from Sonatype.
|
|
222
|
+
val versionString =
|
|
223
|
+
if (versionStringFromFile.isNightly()) {
|
|
224
|
+
"$versionStringFromFile-SNAPSHOT"
|
|
225
|
+
} else {
|
|
226
|
+
versionStringFromFile
|
|
227
|
+
}
|
|
228
|
+
// Returns Maven group for repos using different group for Maven artifacts
|
|
229
|
+
val reactGroupString =
|
|
230
|
+
reactAndroidProperties[INTERNAL_REACT_PUBLISHING_GROUP] as? String
|
|
231
|
+
?: DEFAULT_INTERNAL_REACT_PUBLISHING_GROUP
|
|
232
|
+
val hermesGroupString =
|
|
233
|
+
reactAndroidProperties[INTERNAL_HERMES_PUBLISHING_GROUP] as? String
|
|
234
|
+
?: DEFAULT_INTERNAL_HERMES_PUBLISHING_GROUP
|
|
235
|
+
|
|
236
|
+
val hermesVersionProperties = Properties()
|
|
237
|
+
hermesVersionFile.inputStream().use { hermesVersionProperties.load(it) }
|
|
238
|
+
|
|
239
|
+
val hermesVersionString =
|
|
240
|
+
(hermesVersionProperties[INTERNAL_HERMES_VERSION_NAME] as? String).orEmpty()
|
|
241
|
+
val hermesVersion =
|
|
242
|
+
if (hermesVersionString.startsWith("0.0.0") || "-commitly-" in hermesVersionString) {
|
|
243
|
+
"$hermesVersionString-SNAPSHOT"
|
|
244
|
+
} else {
|
|
245
|
+
hermesVersionString
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
val hermesV1Version =
|
|
249
|
+
(hermesVersionProperties[INTERNAL_HERMES_V1_VERSION_NAME] as? String).orEmpty()
|
|
250
|
+
val isHermesNightly = (project.findProperty(INTERNAL_USE_HERMES_NIGHTLY) as? String).toBoolean()
|
|
251
|
+
|
|
252
|
+
return Coordinates(
|
|
253
|
+
versionString,
|
|
254
|
+
hermesVersion,
|
|
255
|
+
hermesV1Version,
|
|
256
|
+
reactGroupString,
|
|
257
|
+
hermesGroupString,
|
|
258
|
+
isHermesNightly,
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
fun Project.mavenRepoFromUrl(
|
|
263
|
+
url: String,
|
|
264
|
+
action: (MavenArtifactRepository) -> Unit = {},
|
|
265
|
+
): MavenArtifactRepository =
|
|
266
|
+
project.repositories.maven {
|
|
267
|
+
it.url = URI.create(url)
|
|
268
|
+
action(it)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
fun Project.mavenRepoFromURI(
|
|
272
|
+
uri: URI,
|
|
273
|
+
action: (MavenArtifactRepository) -> Unit = {},
|
|
274
|
+
): MavenArtifactRepository =
|
|
275
|
+
project.repositories.maven {
|
|
276
|
+
it.url = uri
|
|
277
|
+
action(it)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
internal fun Project.shouldAddJitPack() =
|
|
281
|
+
when {
|
|
282
|
+
hasProperty(SCOPED_INCLUDE_JITPACK_REPOSITORY) ->
|
|
283
|
+
property(SCOPED_INCLUDE_JITPACK_REPOSITORY).toString().toBoolean()
|
|
284
|
+
hasProperty(INCLUDE_JITPACK_REPOSITORY) ->
|
|
285
|
+
property(INCLUDE_JITPACK_REPOSITORY).toString().toBoolean()
|
|
286
|
+
else -> INCLUDE_JITPACK_REPOSITORY_DEFAULT
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
internal fun String.isNightly(): Boolean = this.startsWith("0.0.0") || "-nightly-" in this
|
|
290
|
+
|
|
291
|
+
internal fun Project.exclusiveEnterpriseRepository() =
|
|
292
|
+
when {
|
|
293
|
+
hasProperty(SCOPED_EXCLUSIVE_ENTEPRISE_REPOSITORY) ->
|
|
294
|
+
property(SCOPED_EXCLUSIVE_ENTEPRISE_REPOSITORY).toString()
|
|
295
|
+
hasProperty(EXCLUSIVE_ENTEPRISE_REPOSITORY) ->
|
|
296
|
+
property(EXCLUSIVE_ENTEPRISE_REPOSITORY).toString()
|
|
297
|
+
else -> null
|
|
298
|
+
}
|
|
299
|
+
}
|
package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
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.utils
|
|
9
|
+
|
|
10
|
+
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
|
|
11
|
+
import com.android.build.api.variant.LibraryAndroidComponentsExtension
|
|
12
|
+
import com.facebook.react.utils.PropertyUtils.INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT
|
|
13
|
+
import org.gradle.api.Action
|
|
14
|
+
import org.gradle.api.JavaVersion
|
|
15
|
+
import org.gradle.api.Project
|
|
16
|
+
import org.gradle.api.plugins.AppliedPlugin
|
|
17
|
+
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
|
18
|
+
|
|
19
|
+
internal object JdkConfiguratorUtils {
|
|
20
|
+
/**
|
|
21
|
+
* Function that takes care of configuring the JDK toolchain for all the projects projects. As we
|
|
22
|
+
* do decide the JDK version based on the AGP version that RNGP brings over, here we can safely
|
|
23
|
+
* configure the toolchain to 17.
|
|
24
|
+
*/
|
|
25
|
+
fun configureJavaToolChains(input: Project) {
|
|
26
|
+
// Check at the app level if react.internal.disableJavaVersionAlignment is set.
|
|
27
|
+
if (input.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
input.rootProject.allprojects { project ->
|
|
31
|
+
// Allows every single module to set react.internal.disableJavaVersionAlignment also.
|
|
32
|
+
if (project.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) {
|
|
33
|
+
return@allprojects
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
val applicationAction =
|
|
37
|
+
Action<AppliedPlugin> {
|
|
38
|
+
project.extensions
|
|
39
|
+
.getByType(ApplicationAndroidComponentsExtension::class.java)
|
|
40
|
+
.finalizeDsl { ext ->
|
|
41
|
+
ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
|
|
42
|
+
ext.compileOptions.targetCompatibility = JavaVersion.VERSION_17
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
val libraryAction =
|
|
46
|
+
Action<AppliedPlugin> {
|
|
47
|
+
project.extensions
|
|
48
|
+
.getByType(LibraryAndroidComponentsExtension::class.java)
|
|
49
|
+
.finalizeDsl { ext ->
|
|
50
|
+
ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
|
|
51
|
+
ext.compileOptions.targetCompatibility = JavaVersion.VERSION_17
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
project.pluginManager.withPlugin("com.android.application", applicationAction)
|
|
55
|
+
project.pluginManager.withPlugin("com.android.library", libraryAction)
|
|
56
|
+
project.pluginManager.withPlugin("org.jetbrains.kotlin.android") {
|
|
57
|
+
project.kotlinExtension.jvmToolchain(17)
|
|
58
|
+
}
|
|
59
|
+
project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
|
60
|
+
project.kotlinExtension.jvmToolchain(17)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|