2

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?

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
Sebastian M
  • 629
  • 7
  • 17

1 Answers1

10

You need to quote it:

it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', '"f4a8ad01f485a8276a6dbc4d364b"'
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491