gpt4 book ai didi

java - 我无法打开我的类,只能找到一个 BuildConfig 文件

转载 作者:行者123 更新时间:2023-12-02 01:54:42 27 4
gpt4 key购买 nike

出于未知原因,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";
}


我尝试恢复它,但它无法像现在刚刚创建的文件一样工作。

最佳答案

在构建时,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));

关于java - 我无法打开我的类,只能找到一个 BuildConfig 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57404432/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com