Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle buildConfigField BuildConfig cannot resolve symbol

I am using Gradle to build my Android application. I am trying to use some flags based on the build type (release or debug).

My Gradle file looks like this:

android {     buildTypes {         debug {             buildConfigField 'boolean', 'PREPROD', 'true'             buildConfigField 'boolean', 'STAGING', 'false'         }          release {             buildConfigField 'boolean', 'PREPROD', 'false'             buildConfigField 'boolean', 'STAGING', 'false'         }     } } 

And if I try to call BuildConfig.PREPROD or BuildConfig.STAGING I get a "Cannot resolve symbol" error. The Gradle sync was successful, so I don't know if I forgot some steps in order to be able to use this feature?

The generated BuildConfig.java file is the following (in build/source/buildConfig/debug/com.example.myapp):

package com.example.myapp;  public final class BuildConfig {   public static final boolean DEBUG = Boolean.parseBoolean("true");   public static final String PACKAGE_NAME = "com.example.myapp";   public static final String BUILD_TYPE = "debug";   public static final String FLAVOR = "";   public static final int VERSION_CODE = 400;   public static final String VERSION_NAME = ""; } 
like image 950
Gaëtan Avatar asked Mar 24 '14 08:03

Gaëtan


People also ask

How is BuildConfig generated?

There's a class called BuildConfig. java which is automatically generated by the build system. This class is updated automatically by Android's build system (like the R class). It already contains a static final boolean called DEBUG, which is normally set to true.

What is BuildConfig flavor?

BuildConfig.FLAVOR gives you combined product flavor. So if you have only one flavor dimension: productFlavors { normal { } admin { } } Then you can just check it: if (BuildConfig. FLAVOR.


1 Answers

Make sure your file is importing the right BuildConfig class. Sometimes if you have other project libraries or modules, it may import the wrong buildConfig. Make sure your import it's like this com.project.app.BuildConfig. I was Having the same issue and the problem was this, Hope it can help somebody.

like image 120
MRodrigues Avatar answered Oct 15 '22 15:10

MRodrigues