Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is no BuildConfig.DEBUG on Android

Tags:

android

I created a new Android project and found out that I cannot use the next piece of code:

if (BuildConfig.DEBUG) {
   //code
}

I tried to find another way to get Debug mode flag on the internet, but I didn't find a new solution, only a very old one. What is the alternative to the BuildConfig.DEBUG flag?

like image 441
Anatol Salanevich Avatar asked Jan 22 '26 06:01

Anatol Salanevich


2 Answers

The reason for the issue is the last version of Gradle: 8.0. Thanks to @cmak I found out the next solution: the in build.gradle file of an app, add the buildFeatures { buildConfig = true } flag.

like image 186
Anatol Salanevich Avatar answered Jan 24 '26 21:01

Anatol Salanevich


If 'android.defaults.buildfeatures.buildconfig = true' is not enough, then perhaps the menu will help: Build -> Rebuild Project.

A 'java (genereted)' folder containing the 'BuildConfig' class should then be created in the project navigator.

Build -> Rebuild must be called separately for each build (release, debug, ...) so that the class is created.

like image 20
guenter47 Avatar answered Jan 24 '26 22:01

guenter47



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!