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

  1. import com.rndiffapp.newarchitecture.components.MainComponentsRegistry;
  2. return BuildConfig.DEBUG;
  3. if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED)

Steps tried to debug:

  1. Adding import com.rndiffapp.BuildConfig; for this file

Issue: Cannot find symbol MainComponentsRegistry File android\app\src\main\java\com\rndiffapp\newarchitecture\MainApplicationReactNativeHost.java

  1. return new MainApplicationTurboModuleManagerDelegate.Builder();
  2. MainComponentsRegistry.register(componentFactory);

Steps tried to debug:

  1. Adding import com.rndiffapp.newarchitecture.components.MainComponentsRegistry; to top of file
  2. Addeding import com.rndiffapp.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate; to top of file

Steps to reproduce:

  1. Follow upgrade guide on https://react-native-community.github.io/upgrade-helper/?from=0.65.1&to=0.68.0
  2. Keep updating files from the top all the way till android/app/src/main/java/com/rndiffapp/MainApplication.java
  3. Open Android studio
  4. Start running any virtual device
  5. run yarn android or npm run react-native

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 9
  • Comments: 31 (6 by maintainers)

Most upvoted comments

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 use import com.projectname.BuildConfig;, where projectname 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

BUILD FAILED in 9s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/Users/user/ReactNativeProj/testProj/android/app/src/main/java/com/testproj/MainApplication.java:39: error: cannot find symbol
          return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
                            ^
  symbol:   variable IS_NEW_ARCHITECTURE_ENABLED
  location: class BuildConfig
/Users/user/ReactNativeProj/testProj/android/app/src/main/java/com/testproj/MainApplication.java:44: error: cannot find symbol
          return BuildConfig.IS_HERMES_ENABLED;
                            ^
  symbol:   variable IS_HERMES_ENABLED
  location: class BuildConfig
/Users/user/ReactNativeProj/testProj/android/app/src/main/java/com/testproj/MainApplication.java:57: error: cannot find symbol
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
                   ^
  symbol:   variable IS_NEW_ARCHITECTURE_ENABLED
  location: class BuildConfig
/Users/user/ReactNativeProj/testProj/android/app/src/main/java/com/testproj/MainApplication.java:57: error: illegal parenthesized expression
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
       ^
4 errors

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

android {
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion rootProject.ext.compileSdkVersion

    namespace "com.testproj" // pay attention to the name 
    defaultConfig {
        applicationId "com.testproj" // same here
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
...

Try adding this to imports in MainApplication.java

  • Add 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

Capture

to enable

  • TurboModules (via MainApplication.java)
  • Fabric (via MainActivity.java)

from gradle.properties when

  • newArchEnabled=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.1

You need to edit your build.gradle file to add a buildConfigField 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

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

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 set namespace "io.projectname.appname" and it worked. Hope it will help someone.

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 use import com.projectname.BuildConfig;, where projectname is the name of my project. Hope this helps someone out there.

This work for me perfectly, And I was not updating, just a new project

import <manifest package name>.BuildConfig; see stackoverflow

In 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 symbol BuildConfig. It was the IS_NEW_ARCHITECTURE_ENABLED symbol as this line was missing:

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

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

defaultConfig {
        applicationId "com.my.app"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "0.0.1"
        buildConfigField "String", "APPLICATION_ID", "\"$applicationId\"" 
        buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true"
        buildConfigField "boolean", "IS_HERMES_ENABLED", "true"
        buildConfigField "boolean", "DEBUG", "true"
    }

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:

import com.my.app.BuildConfig;

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…

Solutions stated above are somewhat obscure

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” the react-native version in your package.json), things might break.

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

What is this? Where would you place it? Is there a code snippet to point you exactly WHERE AND HOW?

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#L142

This is necessary if you enable the New Architecture as it will tell the runtime if you enabled or not the newArchEnabled Gradle Property.

Why is this issue closed? I haven’t found a clear solution yet, neither @swrobel seems yo have gotten a response back…

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.

I updated RN from 0.70.4 to 0.71.2 and I’m facing this issue

BUILD FAILED in 9s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/Users/user/ReactNativeProj/testProj/android/app/src/main/java/com/testproj/MainApplication.java:39: error: cannot find symbol
          return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
                            ^
  symbol:   variable IS_NEW_ARCHITECTURE_ENABLED
  location: class BuildConfig
/Users/user/ReactNativeProj/testProj/android/app/src/main/java/com/testproj/MainApplication.java:44: error: cannot find symbol
          return BuildConfig.IS_HERMES_ENABLED;
                            ^
  symbol:   variable IS_HERMES_ENABLED
  location: class BuildConfig
/Users/user/ReactNativeProj/testProj/android/app/src/main/java/com/testproj/MainApplication.java:57: error: cannot find symbol
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
                   ^
  symbol:   variable IS_NEW_ARCHITECTURE_ENABLED
  location: class BuildConfig
/Users/user/ReactNativeProj/testProj/android/app/src/main/java/com/testproj/MainApplication.java:57: error: illegal parenthesized expression
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
       ^
4 errors

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

android {
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion rootProject.ext.compileSdkVersion

    namespace "com.testproj" // pay attention to the name 
    defaultConfig {
        applicationId "com.testproj" // same here
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
...

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.

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

android {
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion rootProject.ext.compileSdkVersion

    namespace "com.testproj" // pay attention to the name 
    defaultConfig {
        applicationId "com.testproj" // same here
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
...

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 both android/app/build/and android/build, run gradlew clean then start your project again