Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle build generated variable instead of string value [duplicate]

Tags:

android

gradle

I added this code to my build.gradle module: app in android{} section.

 buildTypes.each 
    it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', "f4a8ad01f485a8276a6dbc4d364b"
}

But it's causing error

Error:(14, 57) error: cannot find symbol variable f4a8ad01f485a8276a6dbc4d364b

The OPEN_WEATHER_API_KEY value isn't generated inside of ""

public final class BuildConfig {
     public static final boolean DEBUG = Boolean.parseBoolean("true");
     public static final String APPLICATION_ID ="com.example.weatherforecast";
     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";
     // Fields from build type: debug
     public static final String OPEN_WEATHER_MAP_API_KEY = f4a8ad01f485a8276a6dbc4d364b;
}

In class FetchWeatherTask.java I have this line of code, and it doesn't show any errors.

private final String APP_ID = BuildConfig.OPEN_WEATHER_MAP_API_KEY;

Why in BuildConfig.java OPEN_WEATHER_API_KEY value it's generated as variable instead of String value?

like image 914
Sebastian M Avatar asked Nov 27 '25 14:11

Sebastian M


1 Answers

You need to quote it:

it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', '"f4a8ad01f485a8276a6dbc4d364b"'
like image 195
CommonsWare Avatar answered Nov 30 '25 05:11

CommonsWare



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!