Commit 5bb3a6d
fix: Use FQCN to avoid collisions in PackageList.java (#54736)
Summary:
When two different React Native libraries export a package class with the same name but in different namespaces, the generated PackageList.java causes a compilation error due to ambiguous class references.
The current autolinking generates:
``` kotlin
import com.pikachu.NativeStorage;
import com.snowfox.NativeStorage; // ❌ Compile error: NativeStorage is already defined
public ArrayList<ReactPackage> getPackages() {
return new ArrayList<>(Arrays.<ReactPackage>asList(
new MainReactPackage(mConfig),
new NativeStorage(), // ❌ Ambiguous reference
new NativeStorage() // ❌ Ambiguous reference
));
}
```
Solution:-
Use fully qualified class names (FQCN) instead of imports:
``` kotlin
// No imports needed
public ArrayList<ReactPackage> getPackages() {
return new ArrayList<>(Arrays.<ReactPackage>asList(
new MainReactPackage(mConfig),
// pikachu-storage
new com.pikachu.NativeStorage(),
// snowfox-storage
new com.snowfox.NativeStorage()
));
}
```
## Changelog:
<!-- Help reviewers and the release process by writing your own changelog entry.
Pick one each for the category and type tags:
[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message
For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[ANDROID][FIXED]- Use FQCN to avoid collisions
Pull Request resolved: #54736
Test Plan:
Updated test.
Also tested on my app and RN tester
<img width="687" height="223" alt="image" src="https://github.com/user-attachments/assets/fe54d0c3-4ab4-4d74-a98f-97243851e8c4" />
CI will tell if build fails
Reviewed By: mdvacca
Differential Revision: D88157961
Pulled By: cortinico
fbshipit-source-id: 5fe072dcaed177af1036ca88d55870081a3f42051 parent 41eace0 commit 5bb3a6d
2 files changed
Lines changed: 67 additions & 75 deletions
File tree
- packages/gradle-plugin/react-native-gradle-plugin/src
- main/kotlin/com/facebook/react/tasks
- test/kotlin/com/facebook/react/tasks
Lines changed: 47 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | 52 | | |
54 | | - | |
| 53 | + | |
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
| |||
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
75 | 71 | | |
76 | 72 | | |
77 | 73 | | |
78 | 74 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
92 | 106 | | |
93 | 107 | | |
94 | 108 | | |
| |||
101 | 115 | | |
102 | 116 | | |
103 | 117 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 118 | + | |
| 119 | + | |
108 | 120 | | |
109 | 121 | | |
110 | 122 | | |
| |||
148 | 160 | | |
149 | 161 | | |
150 | 162 | | |
151 | | - | |
152 | | - | |
153 | 163 | | |
154 | 164 | | |
155 | 165 | | |
| |||
Lines changed: 20 additions & 38 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | | - | |
49 | | - | |
50 | | - | |
| 48 | + | |
| 49 | + | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | | - | |
| 53 | + | |
55 | 54 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 55 | + | |
| 56 | + | |
69 | 57 | | |
70 | 58 | | |
71 | 59 | | |
| |||
77 | 65 | | |
78 | 66 | | |
79 | 67 | | |
80 | | - | |
| 68 | + | |
81 | 69 | | |
82 | 70 | | |
83 | 71 | | |
| |||
86 | 74 | | |
87 | 75 | | |
88 | 76 | | |
89 | | - | |
90 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
91 | 81 | | |
92 | 82 | | |
93 | 83 | | |
| |||
226 | 216 | | |
227 | 217 | | |
228 | 218 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
| 219 | + | |
| 220 | + | |
233 | 221 | | |
234 | 222 | | |
235 | 223 | | |
| |||
246 | 234 | | |
247 | 235 | | |
248 | 236 | | |
249 | | - | |
250 | | - | |
251 | 237 | | |
252 | 238 | | |
253 | 239 | | |
| |||
305 | 291 | | |
306 | 292 | | |
307 | 293 | | |
308 | | - | |
309 | 294 | | |
310 | | - | |
| 295 | + | |
311 | 296 | | |
312 | 297 | | |
313 | 298 | | |
| |||
324 | 309 | | |
325 | 310 | | |
326 | 311 | | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | 312 | | |
333 | 313 | | |
334 | 314 | | |
| |||
374 | 354 | | |
375 | 355 | | |
376 | 356 | | |
377 | | - | |
378 | | - | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
379 | 361 | | |
380 | 362 | | |
381 | 363 | | |
| |||
389 | 371 | | |
390 | 372 | | |
391 | 373 | | |
392 | | - | |
| 374 | + | |
393 | 375 | | |
394 | 376 | | |
395 | 377 | | |
| |||
399 | 381 | | |
400 | 382 | | |
401 | 383 | | |
402 | | - | |
| 384 | + | |
403 | 385 | | |
404 | 386 | | |
405 | 387 | | |
| |||
0 commit comments