BuildConfig.DEBUG always returns false
2 min read
If you see the error that
BuildConfig.DEBUG always returns false in Android Studio, this is likely because you've imported another package's BuildConfig instead of your own. Follow the instructions below to fix it.
BuildConfig is a generated class. It gets output to your build folder, which is ignored by source control, so you likely are not realizing the file being generated at all. Many projects appear to expose their BuildConfig class so the intellisense in Android Studio will pick up on these, especially if yours hasn't been generated yet.
Why wouldn't be BuildConfig be generated?
Your BuildConfig may not be generated for a number of reasons:
- The build directory has been deleted
- You did a Project clean via Gradle, which deletes the build directory
- You updated Android Studio and Gradle, which may have a side effect of doing a Gradle clean
How to fix BuildConfig.DEBUG always returns false
Delete any BuildConfig import from the file
Delete any imports that import BuildConfig. You don't need them.
Ignore import prompts
Just ignore the import prompts. Do not import another project's BuildConfig. Of course this will always be false because projects don't ship debug builds. If you haven't generated you're likely to see this error. If you import another package's build config, you're going to get the warning:
BuildConfig.DEBUG: condition is always false.
Run Gradle build
Run the project as usual. You should see this error disappear.
TLDR: BuildConfig is a generated class in your project. If Android Studio can't find it, it'll prompt you to import it. Don't import it or you'll get the lint warning. Run the project as usual, ignoring the red. Your problem should be solved.