React Native Android Build Error MainActivity.java:29: error: cannot find symbol
I had the same issue and it was resolved by simply adding following import statement in MainApplication.java
:
import com.facebook.react.BuildConfig;
The way android knows where to find certain files, and how to connect certain files, is by using fields set in AndroidManifest.xml. Since the default setup of a React Native project, references everything with .(name-of-resource), this means that everything will be resolved with regarding to the package name set in the <manifest>
tag. So for everything to work out of the box, and everything to be generated as expected, the path to MainActivity.java, should be the same as the package name.
example:
your apps package name:
com.mycompanyname.myappname
location of MainActivity.java: android/app/src/main/java/com/mycompanyname/myappname/MainActivity.java
I rebuilt the project with react-native upgrade
.
My issue was then that I had old files that were referencing the old package names (because I changed the name of the app in package.json
). Once deleting those, I resolved the issue.