Skip to content

Fix PackageList.java generation for dependencies with multiple package instances - #57877

Open
SnowingFox wants to merge 1 commit into
react:mainfrom
SnowingFox:fix/issue-55653-autolinking-multiple-package-instances
Open

Fix PackageList.java generation for dependencies with multiple package instances#57877
SnowingFox wants to merge 1 commit into
react:mainfrom
SnowingFox:fix/issue-55653-autolinking-multiple-package-instances

Conversation

@SnowingFox

Copy link
Copy Markdown

Summary:

A dependency that registers multiple React packages via react-native.config.js (e.g. react-native-appsflyer) fails to generate a compiling PackageList.java.

// node_modules/react-native-appsflyer/react-native.config.js
dependency: {
  platforms: {
    android: {
      packageImportPath: [
        'import com.appsflyer.reactnative.RNAppsFlyerPackage;',
        'import com.appsflyer.reactnative.PCAppsFlyerPackage;',
      ].join('\n'),
      packageInstance: [
        'new RNAppsFlyerPackage()',
        'new PCAppsFlyerPackage()',
      ].join(',\n'),
    },
  },
},

PR #54736 introduced FQCN rewriting to avoid class-name collisions, but extractFqcnFromImport uses Regex(...).find(), which only returns the first import match, and the code rewrites only that single short class name in the instance string. The 2nd+ package instances keep a bare short class name with no import, so the generated PackageList.java does not compile:

new com.appsflyer.reactnative.RNAppsFlyerPackage(),
new PCAppsFlyerPackage(),   // cannot find symbol

Fixes #55653

This change extracts the FQCN from every import line and rewrites every bare short class name in the package instance string with its FQCN. Behaviour for the single-package case is unchanged.

Changelog:

[ANDROID] [FIXED] - Autolink: qualify every package instance in the generated PackageList.java when a dependency registers multiple packages

Test Plan:

Added a GeneratePackageListTaskTest case with a dependency providing two imports and two package instances, asserting the generated string contains both FQCNs and no bare new <ShortName>() token.

RED (before the fix) — the new test fails because the 2nd instance stays bare:

GeneratePackageListTaskTest > composePackageInstance_withMultipleImportsInOneDependency_returnsFqcnForEachInstance FAILED
    java.lang.AssertionError:
    Expecting actual:
      ",
          // @react-native/appsflyer
          new com.appsflyer.reactnative.RNAppsFlyerPackage(),
    new PCAppsFlyerPackage()"
    to contain:
      "new com.appsflyer.reactnative.PCAppsFlyerPackage()"
17 tests completed, 1 failed

GREEN (after the fix):

> Task :react-native-gradle-plugin:test
BUILD SUCCESSFUL in 10s

Full react-native-gradle-plugin suite (./gradlew :react-native-gradle-plugin:test --max-workers=2): 216 tests, 0 failures, 0 errors — no regressions.

…e instances

Summary:
Dependencies that register more than one React package via react-native.config.js
(e.g. react-native-appsflyer) supply a packageImportPath with multiple import
statements and a packageInstance with multiple "new X()" expressions. The FQCN
rewriting added in react#54736 only considered the FIRST import, so the 2nd+ package
instances were emitted as bare class names with no import and the generated
PackageList.java failed to compile ("cannot find symbol").

Extract the FQCN from every import line and rewrite every short class name in the
package instance string with its FQCN. Single-instance behaviour is unchanged.

Changelog:
[ANDROID] [FIXED] - Autolink: qualify every package instance in the generated PackageList.java when a dependency registers multiple packages

Test Plan:
Added a GeneratePackageListTaskTest case with a dependency that registers two
packages (two imports, two instances). It failed before the fix (the 2nd instance
was emitted as a bare class name) and passes after. Full react-native-gradle-plugin
suite: 216 tests, 0 failures.

Co-Authored-By: Claude <noreply@anthropic.com>
@meta-cla

meta-cla Bot commented Aug 10, 2026

Copy link
Copy Markdown

Hi @SnowingFox!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Aug 10, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 10, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autolinking android regression

1 participant