由于未知原因,Android Studio项目中的Java文件 从另一个项目的另一个包中有一个BuildConfig类的子箭头
/**
* Automatically generated file. DO NOT MODIFY
*/
package alsayed.aly.maintenanceplaner;
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "alsayed.aly.maintenanceplaner";
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";
}
我尝试还原它,但由于现在刚刚创建的文件,它无法正常工作。
答案 0 :(得分:0)
在构建时,Gradle会生成BuildConfig类,以便您的应用代码可以检查有关当前构建的信息。
您还可以使用buildConfigField()方法从Gradle构建配置文件中将自定义字段添加到BuildConfig类中,并在应用程序的运行时代码中访问这些值。同样,您可以使用resValue()添加应用程序资源值。
android {
...
buildTypes {
release {
// These values are defined only for the release build, which
// is typically used for full builds and continuous builds.
buildConfigField("String", "BUILD_TIME", "\"${minutesSinceEpoch}\"")
resValue("string", "build_time", "${minutesSinceEpoch}")
...
}
debug {
// Use static values for incremental builds to ensure that
// resource files and BuildConfig aren't rebuilt with each run.
// If they were dynamic, they would prevent certain benefits of
// Instant Run as well as Gradle UP-TO-DATE checks.
buildConfigField("String", "BUILD_TIME", "\"0\"")
resValue("string", "build_time", "0")
}
}
}
在您的应用代码中,您可以按以下方式访问属性:
Log.i(TAG, BuildConfig.BUILD_TIME);
Log.i(TAG, getString(R.string.build_time));