Skip to content

Conversation

@riteshshukla04
Copy link
Contributor

@riteshshukla04 riteshshukla04 commented Dec 1, 2025

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:

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:

// 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:

[ANDROID][FIXED]- Use FQCN to avoid collisions

Test Plan:

Updated test.
Also tested on my app and RN tester
image

CI will tell if build fails

@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 Dec 1, 2025
@riteshshukla04 riteshshukla04 marked this pull request as draft December 1, 2025 12:06
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Dec 1, 2025
@riteshshukla04 riteshshukla04 marked this pull request as ready for review December 1, 2025 12:06
@riteshshukla04 riteshshukla04 marked this pull request as draft December 1, 2025 12:07
@cortinico
Copy link
Contributor

This works, thanks for sending it over 👍

@riteshshukla04 riteshshukla04 marked this pull request as ready for review December 1, 2025 12:28
@riteshshukla04
Copy link
Contributor Author

@cortinico do you think we should do a change in react native cli config for this or this works?

@cortinico
Copy link
Contributor

cortinico commented Dec 2, 2025

Nope this is sufficient, we don't need a CLI PR

@meta-codesync
Copy link

meta-codesync bot commented Dec 2, 2025

@cortinico has imported this pull request. If you are a Meta employee, you can view this in D88157961.

internal fun composeFileContent(packageClassInstance: String): String =
generatedFileContentsTemplate
.replace("{{ packageImports }}", packageImports)
.replace("{{ packageImports }}", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just remove this line + remove the {{ packageImports }} from the template?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done @cortinico . Thanks for pointing out

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.

3 participants