Skip to content

new ReactFragment.Builder().setComponentName is ambiguous | Brownfield code breaks. #54396

@HamidShaikh1499

Description

@HamidShaikh1499

Description

I was using react native version 0.79.0 stable version, and I got a major error that crashed the Android 32-bit architecture device due to turbo module listener.

So I had to update React Native from 0.79.0 to 0.81.X because the community fixed that issue. Now the problem occurs after updating to version 0.81.x, then Android IDE is giving an error on new ReactFragment.Builder().setComponentName this line of code, and it says an ambiguous method, which means the builder class has two functions with the same name, and the compiler is confused to call that function.

ReactFragment fragment = new ReactFragment.Builder()
.setComponentName("HelloWorld") // this line has problem.
.setLaunchOptions(launchOptions)
.build();

And the worst thing I found that I thought it would fix in a later version 0.82.X. I updated again version from 0.81.x to 0.82 latest version and I am getting the following problems;

ReactFragment fragment = new ReactFragment.Builder()
.setComponentName("HelloWorld") // Android IDE says an ambiguous method
.setLaunchOptions(launchOptions) // Android IDE doesn't find this function after the builder, giving an error with red color on the function.
.build();

So in the latest version, Java code has broken for brownfield applications and especially for fragment replacement with React native Screen.

Please guide and fix it. I am stuck

Steps to reproduce

  1. You can create a new project, or you can use an existing project with version 0.81 or 0.82.x.
  2. Open the Android folder in Android Studio.
  3. Open any fragment file which written in java or you can create new file for fragment.
  4. paste following code in that file
    ReactFragment fragment = new ReactFragment.Builder()
    .setComponentName("HelloWorld")
    .setLaunchOptions(launchOptions)
    .build();
  5. Now you can find the problems, and the IDE will tell ambiguous method call.

React Native Version

0.81.x

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

I have a good machine with 8 cores and 16 threads and having good space.

Stacktrace or Logs

C:\XXX_USER\ExtraProject\XXX-XXX-v2\android\app\src\main\java\hr\sr\recovery\xxx_project\UI\Center\AddOnVehicle\AdddOnFilesFragment.java:71: error: reference to setComponentName is ambiguous
.setComponentName(AppEnums.ReactNativeModule.addOnVehicle.toString())
              ^
both method setComponentName(String) in Builder and method setComponentName(String) in Builder match

MANDATORY Reproducer

No Play ground please follow above steps to reproduce.

Screenshots and Videos

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: AttentionIssues where the author has responded to feedback.Needs: ReproThis issue could be improved with a clear list of steps to reproduce the issue.Needs: Version Info

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions