Reputation: 5396
I'm getting this error when trying to compile my React Native android app. The Android app can't resolve BuildConfig.DEBUG.
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac
/Users/amirsharif/mobile-rappad/android/app/src/main/java/com/rappadmobile/MainActivity.java:29: error: cannot find symbol
.setUseDeveloperSupport(BuildConfig.DEBUG)
^
symbol: variable BuildConfig
location: class MainActivity
>1 error
:app:compileDebugJavaWithJavac FAILED
I can temporarily resolve it by simply setting it to true. This might've happened after I changed an application name (since that's something I've also been trying to do).
I probably have to change something with Gradle so it generates the right kind of files again.
/**
* Automatically generated file. DO NOT MODIFY
*/
package com.app;
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com.rappadmobile";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0";
}
Upvotes: 114
Views: 126955
Reputation: 11
I just fixed this by making package name same as AndroidManifest.xml on these files;
MainApplication.java, MainActivity.java located in "android/app/src/main/java/com/yourProjectName/"
if you do not have the package simply add
package com.yourAppName;
Upvotes: 0
Reputation: 67
Upgrading react-native solved this error:
react-native upgrade
Now build again:
react-native run-android
Upvotes: 6
Reputation: 2024
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
Upvotes: 107
Reputation: 1
Task :app:compileDebugJavaWithJavac FAILED /media/infiniti/data/React-Native/Blog/BlogApp/android/app/src/main/java/com/anonymous/BlogApp/MainApplication.java:47: error: cannot find symbol return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; Note: alot of errors after BuildConfig. after alot of time i found slon soln: android->app->build.gradle android{ namespace and applicationId must be same} which is "packageNameOfApplication" like com.abcd.YourProjectName
Upvotes: 0
Reputation: 1
I'm currently working with Expo and I ran to this kind of problem. Mine worked when I navigated to android > app > build.gradle
and changed the namespace value from com.company_app
to com.mycompany.myapp
Upvotes: 0
Reputation:
Seems like you have updated your package name in all files but failed to change the name of folder which we will same as your package name.
android < src < main < java < com < "middlen_package_name" < "last_package_name".
ex: com.yourapp.gameapp;
Run the app again but if it still shows this error then ,
check if there is a folder with old package name. Delete this and rebuild again.
Happy Coding.
Upvotes: 1
Reputation: 173
My case was that I renamed the package in one place(AndroidManifest.xml) Ex: The original: com.example Changed it to: com.example.app
Renaming it again solved the problem
Upvotes: 3
Reputation: 1
I fixed it by following these steps: Android Version: From Terminal go to android folder and run this command: gradlew clean
From main project folder delete this folder: node_modules
From menu file: Invalidate caches and restart IDE
Find your MainActivity.java file and add this import line: import com.facebook.react.BuildConfig;
In terminal, go to android folder and run this: gradlew
in terminal, go to main root and run this: yarn install
Now you can start the metro and run the app.
P.S.: Make sure that into the MainActivity.java file the bundleID name is correct. You will find it into the first row. Then, make sure that the MainActivity.java file is located into the correct path like this: project_name/Android/App/src/main/java/1/2/3/MainActivity.java where 1/2/3 must be the name of your bundleID, for example, com/bundle/id
Upvotes: -1
Reputation: 3319
If you renamed your bundle identifier
you will likely need to change:
Your android/app/src/main/....../MainApplication.java
package and imports.
Even though I used react-native-rename
npm package, it did not take care of some files MainApplication.java
and MainActivity.java
.
Upvotes: 14
Reputation: 1274
I experienced this while following https://dev.to/karanpratapsingh/quick-guide-for-updating-package-name-in-react-native-3ei3. I was renaming my application from com.company_app
to com.mycompany.myapp
, apparently, there were some files that I still needed to update but was not included in the guide I was following, I think the guide is only for general, like a fresh react-native app, I solved this by doing a global search for com.company_app
and just replacing each one to com.mycompany.myapp
whenever it makes sense.
Upvotes: 0
Reputation: 998
A combination of some answers helped me, summary:
MainApplication.java
etc.)BUCK
fileUpvotes: 24
Reputation: 4257
In my case, I changed the package name in both the BUCK file and Manifest file.
In the BUCK file, change as following.
android_build_config(
name = "build_config",
package = "NEW_PACKAGE_NAME",
)
android_resource(
name = "res",
package = "NEW_PACKAGE_NAME",
res = "src/main/res", )
Upvotes: 18
Reputation: 503
Check if you have missed installing the react-native-gesture-handler.
yarn add react-native-gesture-handler
npm install --save react-native-gesture-handler
react-native link react-native-gesture-handler
Upvotes: -2
Reputation: 2120
I had the same issue and it was resolved by simply adding following import statement in MainApplication.java
:
import com.facebook.react.BuildConfig;
Upvotes: 150
Reputation: 3853
Delete the old files that might be there in android/app/src/main/java/com
Just keep the file with the new name of the app. Then do react-native upgrade
.
Upvotes: 3
Reputation: 451
In your MainActivity.java
, you can check the first line is package com.YOU_APP_NAME;
If this line does not exist, you should add this.
Upvotes: 45
Reputation: 5396
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.
Upvotes: 47