@react-native/gradle-plugin 0.84.0-nightly-20251203-a5e6addc6 → 0.84.0-nightly-20251205-95cc1e767

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native/gradle-plugin",
3
- "version": "0.84.0-nightly-20251203-a5e6addc6",
3
+ "version": "0.84.0-nightly-20251205-95cc1e767",
4
4
  "description": "Gradle Plugin for React Native",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,11 +34,11 @@ abstract class GeneratePackageListTask : DefaultTask() {
34
34
  JsonUtils.fromAutolinkingConfigJson(autolinkInputFile.get().asFile)
35
35
  ?: error(
36
36
  """
37
- RNGP - Autolinking: Could not parse autolinking config file:
38
- ${autolinkInputFile.get().asFile.absolutePath}
39
-
40
- The file is either missing or not containing valid JSON so the build won't succeed.
41
- """
37
+ RNGP - Autolinking: Could not parse autolinking config file:
38
+ ${autolinkInputFile.get().asFile.absolutePath}
39
+
40
+ The file is either missing or not containing valid JSON so the build won't succeed.
41
+ """
42
42
  .trimIndent()
43
43
  )
44
44
 
@@ -49,9 +49,8 @@ abstract class GeneratePackageListTask : DefaultTask() {
49
49
  )
50
50
 
51
51
  val androidPackages = filterAndroidPackages(model)
52
- val packageImports = composePackageImports(packageName, androidPackages)
53
52
  val packageClassInstance = composePackageInstance(packageName, androidPackages)
54
- val generatedFileContents = composeFileContent(packageImports, packageClassInstance)
53
+ val generatedFileContents = composeFileContent(packageClassInstance)
55
54
 
56
55
  val outputDir = generatedOutputDirectory.get().asFile
57
56
  outputDir.mkdirs()
@@ -61,34 +60,49 @@ abstract class GeneratePackageListTask : DefaultTask() {
61
60
  }
62
61
  }
63
62
 
64
- internal fun composePackageImports(
65
- packageName: String,
66
- packages: Map<String, ModelAutolinkingDependenciesPlatformAndroidJson>,
67
- ) =
68
- packages.entries.joinToString("\n") { (name, dep) ->
69
- val packageImportPath =
70
- requireNotNull(dep.packageImportPath) {
71
- "RNGP - Autolinking: Missing `packageImportPath` in `config` for dependency $name. This is required to generate the autolinking package list."
72
- }
73
- "// $name\n${interpolateDynamicValues(packageImportPath, packageName)}"
74
- }
63
+ /**
64
+ * Extracts the fully qualified class name from an import statement. E.g., "import
65
+ * com.foo.bar.MyClass;" -> "com.foo.bar.MyClass"
66
+ */
67
+ internal fun extractFqcnFromImport(importStatement: String): String? {
68
+ val match = Regex("import\\s+([\\w.]+)\\s*;").find(importStatement)
69
+ return match?.groupValues?.get(1)
70
+ }
75
71
 
76
72
  internal fun composePackageInstance(
77
73
  packageName: String,
78
74
  packages: Map<String, ModelAutolinkingDependenciesPlatformAndroidJson>,
79
- ) =
80
- if (packages.isEmpty()) {
81
- ""
82
- } else {
83
- ",\n " +
84
- packages.entries.joinToString(",\n ") { (name, dep) ->
85
- val packageInstance =
86
- requireNotNull(dep.packageInstance) {
87
- "RNGP - Autolinking: Missing `packageInstance` in `config` for dependency $name. This is required to generate the autolinking package list."
88
- }
89
- interpolateDynamicValues(packageInstance, packageName)
90
- }
91
- }
75
+ ): String {
76
+ if (packages.isEmpty()) {
77
+ return ""
78
+ }
79
+
80
+ val instances =
81
+ packages.entries.map { (name, dep) ->
82
+ val packageInstance =
83
+ requireNotNull(dep.packageInstance) {
84
+ "RNGP - Autolinking: Missing `packageInstance` in `config` for dependency $name. This is required to generate the autolinking package list."
85
+ }
86
+ val packageImportPath = dep.packageImportPath
87
+ val interpolated = interpolateDynamicValues(packageInstance, packageName)
88
+
89
+ // Use FQCN to avoid class name collisions between different packages
90
+ val fqcn = extractFqcnFromImport(interpolateDynamicValues(packageImportPath, packageName))
91
+ val fqcnInstance =
92
+ if (fqcn != null) {
93
+ val className = fqcn.substringAfterLast('.')
94
+ // Replace the short class name with FQCN in the instance
95
+ interpolated.replace(Regex("\\b${Regex.escape(className)}\\b")) { fqcn }
96
+ } else {
97
+ interpolated
98
+ }
99
+
100
+ // Add comment with package name before each instance
101
+ "// $name\n $fqcnInstance"
102
+ }
103
+
104
+ return ",\n " + instances.joinToString(",\n ")
105
+ }
92
106
 
93
107
  internal fun filterAndroidPackages(
94
108
  model: ModelAutolinkingConfigJson?
@@ -101,10 +115,8 @@ abstract class GeneratePackageListTask : DefaultTask() {
101
115
  .associate { it.name to checkNotNull(it.platforms?.android) }
102
116
  }
103
117
 
104
- internal fun composeFileContent(packageImports: String, packageClassInstance: String): String =
105
- generatedFileContentsTemplate
106
- .replace("{{ packageImports }}", packageImports)
107
- .replace("{{ packageClassInstances }}", packageClassInstance)
118
+ internal fun composeFileContent(packageClassInstance: String): String =
119
+ generatedFileContentsTemplate.replace("{{ packageClassInstances }}", packageClassInstance)
108
120
 
109
121
  companion object {
110
122
  const val GENERATED_FILENAME = "com/facebook/react/PackageList.java"
@@ -148,8 +160,6 @@ abstract class GeneratePackageListTask : DefaultTask() {
148
160
  import java.util.Arrays;
149
161
  import java.util.ArrayList;
150
162
 
151
- {{ packageImports }}
152
-
153
163
  @SuppressWarnings("deprecation")
154
164
  public class PackageList {
155
165
  private Application application;
@@ -43,29 +43,17 @@ class GeneratePackageListTaskTest {
43
43
  }
44
44
 
45
45
  @Test
46
- fun composePackageImports_withNoPackages_returnsEmpty() {
46
+ fun extractFqcnFromImport_withValidImport_returnsClassName() {
47
47
  val task = createTestTask<GeneratePackageListTask>()
48
- val packageName = "com.facebook.react"
49
- val result = task.composePackageImports(packageName, emptyMap())
50
- assertThat(result).isEqualTo("")
48
+ val result = task.extractFqcnFromImport("import com.facebook.react.APackage;")
49
+ assertThat(result).isEqualTo("com.facebook.react.APackage")
51
50
  }
52
51
 
53
52
  @Test
54
- fun composePackageImports_withPackages_returnsImportCorrectly() {
53
+ fun extractFqcnFromImport_withInvalidImport_returnsNull() {
55
54
  val task = createTestTask<GeneratePackageListTask>()
56
- val packageName = "com.facebook.react"
57
-
58
- val result = task.composePackageImports(packageName, testDependencies)
59
- assertThat(result)
60
- .isEqualTo(
61
- """
62
- // @react-native/a-package
63
- import com.facebook.react.aPackage;
64
- // @react-native/another-package
65
- import com.facebook.react.anotherPackage;
66
- """
67
- .trimIndent()
68
- )
55
+ val result = task.extractFqcnFromImport("invalid import statement")
56
+ assertThat(result).isNull()
69
57
  }
70
58
 
71
59
  @Test
@@ -77,7 +65,7 @@ class GeneratePackageListTaskTest {
77
65
  }
78
66
 
79
67
  @Test
80
- fun composePackageInstance_withPackages_returnsImportCorrectly() {
68
+ fun composePackageInstance_withPackages_returnsFqcnCorrectly() {
81
69
  val task = createTestTask<GeneratePackageListTask>()
82
70
  val packageName = "com.facebook.react"
83
71
 
@@ -86,8 +74,10 @@ class GeneratePackageListTaskTest {
86
74
  .isEqualTo(
87
75
  """
88
76
  ,
89
- new APackage(),
90
- new AnotherPackage()
77
+ // @react-native/a-package
78
+ new com.facebook.react.APackage(),
79
+ // @react-native/another-package
80
+ new com.facebook.react.AnotherPackage()
91
81
  """
92
82
  .trimIndent()
93
83
  )
@@ -226,10 +216,8 @@ class GeneratePackageListTaskTest {
226
216
  @Test
227
217
  fun composeFileContent_withNoPackages_returnsValidFile() {
228
218
  val task = createTestTask<GeneratePackageListTask>()
229
- val packageName = "com.facebook.react"
230
- val imports = task.composePackageImports(packageName, emptyMap())
231
- val instance = task.composePackageInstance(packageName, emptyMap())
232
- val result = task.composeFileContent(imports, instance)
219
+ val instance = task.composePackageInstance("com.facebook.react", emptyMap())
220
+ val result = task.composeFileContent(instance)
233
221
  // language=java
234
222
  assertThat(result)
235
223
  .isEqualTo(
@@ -246,8 +234,6 @@ class GeneratePackageListTaskTest {
246
234
  import java.util.Arrays;
247
235
  import java.util.ArrayList;
248
236
 
249
-
250
-
251
237
  @SuppressWarnings("deprecation")
252
238
  public class PackageList {
253
239
  private Application application;
@@ -305,9 +291,8 @@ class GeneratePackageListTaskTest {
305
291
  fun composeFileContent_withPackages_returnsValidFile() {
306
292
  val task = createTestTask<GeneratePackageListTask>()
307
293
  val packageName = "com.facebook.react"
308
- val imports = task.composePackageImports(packageName, testDependencies)
309
294
  val instance = task.composePackageInstance(packageName, testDependencies)
310
- val result = task.composeFileContent(imports, instance)
295
+ val result = task.composeFileContent(instance)
311
296
  // language=java
312
297
  assertThat(result)
313
298
  .isEqualTo(
@@ -324,11 +309,6 @@ class GeneratePackageListTaskTest {
324
309
  import java.util.Arrays;
325
310
  import java.util.ArrayList;
326
311
 
327
- // @react-native/a-package
328
- import com.facebook.react.aPackage;
329
- // @react-native/another-package
330
- import com.facebook.react.anotherPackage;
331
-
332
312
  @SuppressWarnings("deprecation")
333
313
  public class PackageList {
334
314
  private Application application;
@@ -374,8 +354,10 @@ class GeneratePackageListTaskTest {
374
354
  public ArrayList<ReactPackage> getPackages() {
375
355
  return new ArrayList<>(Arrays.<ReactPackage>asList(
376
356
  new MainReactPackage(mConfig),
377
- new APackage(),
378
- new AnotherPackage()
357
+ // @react-native/a-package
358
+ new com.facebook.react.APackage(),
359
+ // @react-native/another-package
360
+ new com.facebook.react.AnotherPackage()
379
361
  ));
380
362
  }
381
363
  }
@@ -389,7 +371,7 @@ class GeneratePackageListTaskTest {
389
371
  "@react-native/a-package" to
390
372
  ModelAutolinkingDependenciesPlatformAndroidJson(
391
373
  sourceDir = "./a/directory",
392
- packageImportPath = "import com.facebook.react.aPackage;",
374
+ packageImportPath = "import com.facebook.react.APackage;",
393
375
  packageInstance = "new APackage()",
394
376
  buildTypes = emptyList(),
395
377
  libraryName = "aPackage",
@@ -399,7 +381,7 @@ class GeneratePackageListTaskTest {
399
381
  "@react-native/another-package" to
400
382
  ModelAutolinkingDependenciesPlatformAndroidJson(
401
383
  sourceDir = "./another/directory",
402
- packageImportPath = "import com.facebook.react.anotherPackage;",
384
+ packageImportPath = "import com.facebook.react.AnotherPackage;",
403
385
  packageInstance = "new AnotherPackage()",
404
386
  buildTypes = emptyList(),
405
387
  libraryName = "anotherPackage",