react-native: [Android] [0.68.0] Cannot find symbols for new architecture upgrade
New Version
0.68.0
Old Version
0.65.1
Build Target(s)
Android - Pixel 4 (API 32)
Output of react-native info
System: OS: Windows 10 10.0.19042 CPU: (6) x64 Intel® Core™ i5-9400F CPU @ 2.90GHz Memory: 18.33 GB / 31.94 GB Binaries: Node: 16.14.0 - C:\Program Files\nodejs\node.EXE Yarn: 3.1.1 - ~\AppData\Roaming\npm\yarn.CMD npm: 8.3.1 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: AllowAllTrustedApps: Disabled IDEs: Android Studio: Version 2021.1.0.0 AI-211.7628.21.2111.8193401 Visual Studio: 17.0.31912.275 (Visual Studio Community 2022) Languages: Java: 1.8.0_312 npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.68.0 => 0.68.0 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found
Issue and Reproduction Steps
Issue: Cannot find symbol BuildConfig
Places issues detected:
File android\app\src\main\java\com\rndiffapp\MainApplication.java
import com.rndiffapp.newarchitecture.components.MainComponentsRegistry;
return BuildConfig.DEBUG;
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED)
Steps tried to debug:
- Adding
import com.rndiffapp.BuildConfig;
for this file
Issue: Cannot find symbol MainComponentsRegistry
File android\app\src\main\java\com\rndiffapp\newarchitecture\MainApplicationReactNativeHost.java
return new MainApplicationTurboModuleManagerDelegate.Builder();
MainComponentsRegistry.register(componentFactory);
Steps tried to debug:
- Adding
import com.rndiffapp.newarchitecture.components.MainComponentsRegistry;
to top of file - Addeding
import com.rndiffapp.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate;
to top of file
Steps to reproduce:
- Follow upgrade guide on https://react-native-community.github.io/upgrade-helper/?from=0.65.1&to=0.68.0
- Keep updating files from the top all the way till
android/app/src/main/java/com/rndiffapp/MainApplication.java
- Open Android studio
- Start running any virtual device
- run
yarn android
ornpm run react-native
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 9
- Comments: 31 (6 by maintainers)
I had a similar issue, but unrelated to upgrading. Nonetheless I had a similar fix. Instead of
import com.facebook.react.BuildConfig;
I had to useimport com.projectname.BuildConfig;
, whereprojectname
is the name of my project. Hope this helps someone out there.I updated RN from 0.70.4 to 0.71.2 and I’m facing this issue
NOTE: Ok, got it. The error was caused because in android/app/build.gradle the applicationId got the name wrong, so yeah, pay attention to the name so that it’s the same as the original.:
Try adding this to imports in
MainApplication.java
import com.facebook.react.BuildConfig;
Note: where is
rndiffapp
should be exchanged for the corresponding one of your project. If you’ve already done this, just ignore it.the diff can b a bit… iffy at times 😅 here’s what we want
https://react-native-community.github.io/upgrade-helper/?from=0.65.1&to=0.69.0-rc.0
to enable
MainApplication.java
)MainActivity.java
)from
gradle.properties
whennewArchEnabled=true
if that helps clarify @swrobel
As @finnp and @swrobel already mentioned, the issue is that you bumped your RN version to 0.68 without using
react-native upgrade
or the Upgrade Helper: https://react-native-community.github.io/upgrade-helper/?from=0.65.1&to=0.68.1You need to edit your
build.gradle
file to add abuildConfigField
for “IS_NEW_ARCHITECTURE_ENABLED”, otherwise it won’t be possible to know at runtime if the New Architecture is enabled or not.Closing as this looks resolved, feel free to reopen if this is not the case.
Thank you @hadnet our issue was the namespace should not be the same as applicationId. namespace needs to be same as the value used at top of MainActivity.java, MainApplication.java, and ReactNativeFlipper.java for the package.
so importing BuildConfig in MainApplication.java is not needed
I don’t understand.
Getting this same error out of nowhere, because I was already working with RN 68.1. I was able to run the Android app and to generate AAB and APK files. With all the stuff that gets auto generated it’s imposible for me to say when and where this started happening.
Solutions stated above are somewhat obscure
What is this? Where would you place it? Is there a code snippet to point you exactly WHERE AND HOW?
Why is this issue closed? I haven’t found a clear solution yet, neither @swrobel seems yo have gotten a response back…
Solved this issue by setting correct namespace value, in my case i had
/io/projectname/appname/MainAcitivity.java
so I setnamespace "io.projectname.appname"
and it worked. Hope it will help someone.This work for me perfectly, And I was not updating, just a new project
import <manifest package name>.BuildConfig;
see stackoverflowIn my case react native upgrade had failed to upgrade
android/app/build.gradle
. Not sure why, but adding these missing changes resolved the issues. However I realize that my issue wasn’t the symbolBuildConfig
. It was theIS_NEW_ARCHITECTURE_ENABLED
symbol as this line was missing:@joshAntoniuk I encountered the same issue as you. To fix this issue I’ve added buildConfigField in the defaultConfig found in “android\app\build.gradle” like this:
Then I’ve added an import where the BuildConfig fields are used. In my case I’ve to add the import to MainApplication.java and AppProvider.java like this:
Hope this will help someone getting stuck. 😃
Still have this issue. My namespaces, packages, and imports are all correct and matching. npx expo run:android works, but building or running the release version crashes with the ReactNativeFlipper cannot find symbol error. Ive been stuck on this for the past week and still can’t figure it out…
Your
build.gradle
files should reflect the same files we have in our/template
folder. If they don’t (i.e. if you just “bump” thereact-native
version in your package.json), things might break.This is a buildConfigField from Android. You can read more about it here: https://developer.android.com/studio/build/gradle-tips#share-custom-fields-and-resource-values-with-your-app-code
It’s needed to be placed inside your
android/app/build.gradle
file like here: https://github.com/facebook/react-native/blob/main/template/android/app/build.gradle#L142This is necessary if you enable the New Architecture as it will tell the runtime if you enabled or not the
newArchEnabled
Gradle Property.This issue is closed because, as I previously said, the upgrade process was not followed properly. We have the Upgrade Helper tool that explains steps by steps how to update your files and setup. If some of those steps are missed (i.e. you forget to edit a build.gradle file) things will not work properly.
I hope this clarifies @piscespieces
I just came across this after updating from 0.69 to 0.72. Couldn’t solve it so installed a fresh RN app and saw that there was no
import com.facebook.react.BuildConfig
. I literally just removed the import and it built fine.Yeah this is the solution, thank you
@akshitrcrm, that was my issue too…
Here’s a great video with the solution https://www.youtube.com/watch?v=TSfE-4CVgDU
Check to make sure your namespace and packages names are correct.
Excellent! But in my case the applicationId is dynamic, it is different for debug and release builds so how do I give the namespace a dynamic value rather than a static value?
applicationIdSuffix ".debug"
important thing, if you have changed the project name be sure to delete
build
folders on bothandroid/app/build/
andandroid/build
, rungradlew clean
then start your project again