react-native: cannot find symbol ReactNativeFlipper.initializeFlipper

Description

I use react-native “0.71.2”

When I want to release the project gradlew assembleRelease I get an error

\android\app\src\main\java\com\dorna\MainApplication.java:62: error: cannot find symbol ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager());

I think the ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); at then end of MainApplication.java line was added recently and caused problem.

Version

0.71.2

Output of npx react-native info

System: OS: Windows 10 10.0.19045 CPU: (12) x64 Intel® Core™ i5-10400 CPU @ 2.90GHz Memory: 19.04 GB / 31.79 GB Binaries: Node: 16.14.2 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD npm: 8.5.0 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: Not Found IDEs: Android Studio: Not Found Visual Studio: Not Found Languages: Java: 11.0.17 npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.2 => 0.71.2 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

When I run gradlew assembleRelease

Snack, code example, screenshot, or link to a repository

gradlew assembleRelease

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 27 (3 by maintainers)

Most upvoted comments

In my case, the issue was that I copied the class from the React Native Upgrade Helper and forgot to change the package from ‘com.rndiffapp’ to my project’s package name (i.e. the same package declared in MainApplication.java).

Fixed the problem by changing the package ‘com.rndiffapp’ from android/app/src/release/java/com/mypackagename/ReactNativeFlipper.java to the package from MainApplication.java

Do you have this file:

android/app/src/release/java/com/helloworld/ReactNativeFlipper.java

in your project with this content: https://github.com/facebook/react-native/blob/main/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.java ?

yes

problem was fixed when I add ReactNativeFlipper.java to the path android\app\src\main\java\com_packageName_

@atn508 it throws error about duplicate class

@alex-mironov It looks like you have a build type called releaseDev (based on Task :app:compileReleaseDevJavaWithJavac FAILED). I’m dealing with the same error when I build releaseStaging.

I suspect the solution for you is to create an additional stub file for that build type at android/app/src/releaseDev/java/com/MY_APP/ReactNativeFlipper.java. I’m still waiting for CI to prove this solution works for my project.

Edit: Yep, adding that file in a directory matching the build type fixed the error in my project.

I change my app Id in build.gradle , MainApplication.java and MainActivity.java and i get this error .

I fixed the problem by changing the package name as the other 3 files in

-android/app/src/release/java/com/my-project-name/ReactNativeFlipper.java -android/app/src/debug/java/com/my-project-name/ReactNativeFlipper.java

To build off of @joshAntoniuk, in my case I had forgot to add in the release version of the ReactNativeFlipper.java file, so I simply copied in the one from the debug folder, but it is not the same. The ReactNativeFlipper.java file in the release/main folder is different than the one in the debug.

Check the React Native Upgrade tool to compare and make sure you have the right file for debug and the right file for release/main.

See: https://react-native-community.github.io/upgrade-helper/?from=0.64.3&to=0.72.4

Here is the release/main version:

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * <p>This source code is licensed under the MIT license found in the LICENSE file in the root
 * directory of this source tree.
 */
package com.rndiffapp;

import android.content.Context;
import com.facebook.react.ReactInstanceManager;

/**
 * Class responsible of loading Flipper inside your React Native application. This is the release
 * flavor of it so it's empty as we don't want to load Flipper.
 */
public class ReactNativeFlipper {
  public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
    // Do nothing as we don't want to initialize Flipper on Release.
  }
}

@atn508 it throws error about duplicate class

this is how i fixed the duplicate class error:

You should have only two ReactNativeFlipper in the following locations:

android/app/src/debug/java/com/helloworld/ReactNativeFlipper.java android/app/src/release/java/com/helloworld/ReactNativeFlipper.java

I had put ReactNativeFlipper.java under /src/main/java/com/… which is what threw the error

yes

problem was fixed when I add ReactNativeFlipper.java to the path android\app\src\main\java\com_packageName_

Closing as the user reported the issue as fixed

Do you have this file:

android/app/src/release/java/com/helloworld/ReactNativeFlipper.java

in your project with this content: https://github.com/facebook/react-native/blob/main/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.java ?

this link 404’s

For some reason I’m still getting the same error:

 > Task :app:compileReleaseDevJavaWithJavac FAILED
 /Users/runner/work/1/s/android/app/src/main/java/com/MY_APP/MainApplication.java:64: error: cannot find symbol
     ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
     ^
   symbol:   variable ReactNativeFlipper
   location: class MainApplication
 Note: /Users/runner/work/1/s/android/app/src/main/java/com/MY_APP/MainActivity.java uses or overrides a deprecated API.
 Note: Recompile with -Xlint:deprecation for details.
 1 error
 w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions
 
 FAILURE: Build completed with 2 failures.
 
 1: Task failed with an exception.
 -----------
 * What went wrong:
 Execution failed for task ':app:compileReleaseDevJavaWithJavac'.
 > Compilation failed; see the compiler error output for details.
 
 * Try:
 > Run with --stacktrace option to get the stack trace.
 > Run with --info or --debug option to get more log output.
 > Run with --scan to get full insights.
 ==============================================================================
 

Package name is correct in both files:

	modified:   android/app/src/debug/java/com/MY_APP/ReactNativeFlipper.java
	modified:   android/app/src/release/java/com/MY_APP/ReactNativeFlipper.java

and android/app/src/release/java/com/MY_APP/ReactNativeFlipper.java:

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * 
 * <p>This source code is licensed under the MIT license found in the LICENSE file in the root
 * directory of this source tree.
 */
package com.MY_APP;
import android.content.Context;
import com.facebook.react.ReactInstanceManager;
/**
 * Class responsible of loading Flipper inside your React Native application. This is the release
 * flavor of it so it's empty as we don't want to load Flipper.
 */
public class ReactNativeFlipper {
  public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
    // Do nothing as we don't want to initialize Flipper on Release.
  }
}

Would appreciate any ideas of what could be wrong 🙏

@atn508 it throws error about duplicate class

Did you solve it ?

What does your MainApplication.java file look like?

Also did you cd ./android && ./gradlew clean before building?

//ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
String packagePath = "com.myproject";
if(BuildConfig.DEBUG){
    try{
        Class flipperClass = Class.forName(packagePath + ".ReactNativeFlipper");
        Method method = flipperClass.getMethod("initializeFlipper");
        method.invoke(null,this,getReactNativeHost().getReactInstanceManager());
    }catch (Exception e){
        e.printStackTrace();
    }
}

yes

problem was fixed when I add ReactNativeFlipper.java to the path android\app\src\main\java\com_packageName_

please help in ReactNativeFlipper.java file What code will you put in the file? my ReactNativeFlipper.java is empty

I ended up figuring it out. I had to create a blank ReactNativeFlipper class in that Build’s folder. Then I had to run EAS update configure. After that my project worked, not sure if it’ll work with your solution though. It is worth mentioning that opening the project in Android Studio and manually changing the build variants highlights potential issues with the project.

In our case, the release/ folder was added to the .gitignore so the CI was failing because the ReactNativeFlipper.java was not checked in to the repo