我将此代码添加到我的build.gradle模块:android {}部分的应用程序。
buildTypes.each
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', "f4a8ad01f485a8276a6dbc4d364b"
}
但它导致错误
错误:(14,57)错误:找不到符号变量 f4a8ad01f485a8276a6dbc4d364b
OPEN_WEATHER_API_KEY值未在"""
内生成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;
}
在类FetchWeatherTask.java中,我有这行代码,并没有显示任何错误。
private final String APP_ID = BuildConfig.OPEN_WEATHER_MAP_API_KEY;
为什么BuildConfig.java OPEN_WEATHER_API_KEY
将值生成为变量而非String值?
答案 0 :(得分:10)
你需要引用它:
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', '"f4a8ad01f485a8276a6dbc4d364b"'