Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] [0.68.0] Cannot find symbols for new architecture upgrade #33623

Closed
Mingyang-Li opened this issue Apr 13, 2022 · 31 comments
Closed

[Android] [0.68.0] Cannot find symbols for new architecture upgrade #33623

Mingyang-Li opened this issue Apr 13, 2022 · 31 comments
Labels
Platform: Android Android applications. Resolution: Answered When the issue is resolved with a simple answer Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) Type: Upgrade Issue Issues reported from upgrade issue form

Comments

@Mingyang-Li
Copy link

Mingyang-Li commented Apr 13, 2022

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(R) Core(TM) 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
@Mingyang-Li Mingyang-Li added Needs: Triage 🔍 Type: Upgrade Issue Issues reported from upgrade issue form labels Apr 13, 2022
@react-native-bot react-native-bot added the Platform: Android Android applications. label Apr 13, 2022
@RalissonMattias
Copy link

RalissonMattias commented Apr 14, 2022

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.

@finnp
Copy link
Contributor

finnp commented Apr 25, 2022

I've run into the same issue when running react-native upgrade. Suggestion with BuildConfig didn't help and also wasn't really found here: https://react-native-community.github.io/upgrade-helper/?from=0.67.2&to=0.68.1

@finnp
Copy link
Contributor

finnp commented Apr 25, 2022

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()

@Mingyang-Li
Copy link
Author

@finnp Ummm I'm gonna give your trick a try - will let you know

@swrobel
Copy link
Contributor

swrobel commented Apr 29, 2022

@finnp where'd you get this from and where does it go? I don't see buildConfigField in any of my app's files (or anywhere in RNDiffApp for that matter)

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

@cortinico cortinico added the Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) label May 2, 2022
@cortinico
Copy link
Contributor

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.

@leotm
Copy link
Contributor

leotm commented May 5, 2022

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

@piscespieces
Copy link

piscespieces commented Jun 7, 2022

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

@cortinico
Copy link
Contributor

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

@cortinico cortinico added Resolution: Answered When the issue is resolved with a simple answer and removed Needs: Triage 🔍 labels Jun 15, 2022
@marlonschlosshauer
Copy link

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.

@huanguolin
Copy link

import <manifest package name>.BuildConfig;
see stackoverflow

@rekiemfaxaf
Copy link

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

@hadnet
Copy link

hadnet commented Feb 16, 2023

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"
    }
...

@beisert1
Copy link

beisert1 commented Feb 17, 2023

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

@chemiadel
Copy link

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

@Mukhammadjon-Jalolov
Copy link

Mukhammadjon-Jalolov commented Feb 28, 2023

Hi everyone.

  • I created a completely new architecture app using: npx react-native@latest init FabricApp
  • Then I enabled: newArchEnabled=true in gradle.properties
  • I followed the steps exactly as written in the documentation to use a Fabric Component
    But when I run yarn android command I'm getting cannot find symbol error. I cannot figure out what's getting wrong in this case. Thank you in advance

Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 C:\Users\User\Documents\FabricApp\node_modules\rtn-centered-text\android\src\main\java\com\rtncenteredtext\CenteredTextManager.java:16: error: cannot find symbol public class CenteredTextManager extends SimpleViewManager<RTNCenteredText> implements RTNCenteredTextManagerInterface<RTNCenteredText> { ___________________________________________^

@ShadyXV
Copy link

ShadyXV commented Mar 14, 2023

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

Seems like having the same value for namespace and applicationId was causing the issue in my project too. I tried so many things but nothing else worked for me.

@pranavbabu
Copy link

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.

@KaivG
Copy link

KaivG commented Apr 1, 2023

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 started an expo project, ejected and the ReactNativeFlipper.java had the namespace specified as package, but MainActivity.java and MainApplication.java had the applicationId specified as package.

Changing it to the package name (Not the applicationId!) everywhere fixed it. Note that I had two ReactNativeFlipper.java files in my android folder and changed both.

@hkvongit
Copy link

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 worked for me. My sleep got saved.

@AguSandoval
Copy link

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.

You're right, I just noticed this started happening right after changing my app namespace in build.gradle file.

thanks!

@aj019
Copy link

aj019 commented Jun 25, 2023

Check the namespace value in app/build.gradle . For me fixing the namespace to the package name of the app fixed the issue. Hope it helps others.

@akshitrcrm
Copy link

akshitrcrm commented Jul 11, 2023

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"

@tholmgren
Copy link

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

@RhamHarts
Copy link

I have a problem that is almost similar to this. I made an android project from react native and expo. when I try to build the application the error appears like this


> Task :app:compileDebugJavaWithJavac
D:\Projek Data posyandu\New folder\amonisasi\android\app\src\main\java\com\hamirz\amonisasi\MainActivity.java:3: error: cannot find symbol
import com.hamirz.amonisasi.BuildConfig;
                           ^
  symbol:   class BuildConfig
  location: package com.hamirz.amonisasi
D:\Projek Data posyandu\New folder\amonisasi\android\app\src\main\java\com\hamirz\amonisasi\MainApplication.java:3: error: cannot find symbol
import com.hamirz.amonisasi.BuildConfig;
                           ^
  symbol:   class BuildConfig
  location: package com.hamirz.amonisasi
D:\Projek Data posyandu\New folder\amonisasi\android\app\src\main\java\com\hamirz\amonisasi\MainActivity.java:40: error: cannot find symbol
    return new ReactActivityDelegateWrapper(this, BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, new DefaultReactActivityDelegate(                                                  ^
  symbol:   variable BuildConfig
  location: class MainActivity
D:\Projek Data posyandu\New folder\amonisasi\android\app\src\main\java\com\hamirz\amonisasi\MainApplication.java:28: error: 
cannot find symbol
        return BuildConfig.DEBUG;
               ^
  symbol: variable BuildConfig
D:\Projek Data posyandu\New folder\amonisasi\android\app\src\main\java\com\hamirz\amonisasi\MainApplication.java:47: error: 
cannot find symbol
        return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
               ^
  symbol: variable BuildConfig
D:\Projek Data posyandu\New folder\amonisasi\android\app\src\main\java\com\hamirz\amonisasi\MainApplication.java:52: error: 
cannot find symbol
        return BuildConfig.IS_HERMES_ENABLED;
               ^
  symbol: variable BuildConfig
D:\Projek Data posyandu\New folder\amonisasi\android\app\src\main\java\com\hamirz\amonisasi\MainApplication.java:65: error: 
cannot find symbol
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
        ^
  symbol:   variable BuildConfig
  location: class MainApplication
D:\Projek Data posyandu\New folder\amonisasi\android\app\src\main\java\com\hamirz\amonisasi\MainApplication.java:65: error: 
illegal parenthesized expression
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
       ^
8 errors

> Task :app:compileDebugJavaWithJavac FAILED
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:compileDebugJavaWithJavac'.
> 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)

* 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.
==============================================================================

* Get more help at https://help.gradle.org

what i already tried :
1.)i already tried to change the gradle version from 7.5.1 which is default from folder to 8.2.1 newest version.

2.)try to compatible the java version with kotlin version.

and the same error still appear like this.

@joshAntoniuk
Copy link

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

@joshAntoniuk
Copy link

I have noticed that building the project in the 'debug' variant creates a BuildConfig.java which builds and runs smoothly - but when building with the 'release' variant the BuildConfig.java is not created - which creates the error. Any ideas on this? Been stuck on it for a couple weeks...

@cirilojesus
Copy link

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

@jede87
Copy link

jede87 commented Oct 31, 2023

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

@jeetvani
Copy link

jeetvani commented Nov 6, 2023

Solution Found - : https://stackoverflow.com/a/77428914/16116610

@b8ne
Copy link

b8ne commented Nov 9, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android Android applications. Resolution: Answered When the issue is resolved with a simple answer Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) Type: Upgrade Issue Issues reported from upgrade issue form
Projects
None yet
Development

No branches or pull requests