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)
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 fromMainApplication.java
Do you have this file:
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 onTask :app:compileReleaseDevJavaWithJavac FAILED
). I’m dealing with the same error when I buildreleaseStaging
.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:
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
Closing as the user reported the issue as fixed
this link 404’s
For some reason I’m still getting the same error:
Package name is correct in both files:
and
android/app/src/release/java/com/MY_APP/ReactNativeFlipper.java
:Would appreciate any ideas of what could be wrong 🙏
Did you solve it ?
What does your MainApplication.java file look like?
Also did you
cd ./android && ./gradlew clean
before building?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