gpt4 book ai didi

Android:如何从已知枚举中设置 gradle 值

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:34:20 27 4
gpt4 key购买 nike

我使用 Logger库在我的开发中,我在我的应用程序类中配置它:

@Override
public void onCreate() {
super.onCreate();
sInstance = this;

Logger.init(BuildConfig.LOGGER_TAG_NAME)
//.setMethodCount(3) // default 2
//.hideThreadInfo() // default shown
.setLogLevel(LogLevel.NONE); // default LogLevel.FULL

LogLevel 是一个枚举(在 Logger 库中)。

但我想根据我的 gradle 构建类型自动设置日志级别;做这样的事情:

buildTypes {

debug {
debuggable true

buildConfigField "enum", "LOGGER_LEVEL", LogLevel.FULL
}

release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

buildConfigField "enum", "LOGGER_LEVEL", LogLevel.NONE
}
}

然后:

Logger.init(BuildConfig.LOGGER_TAG_NAME)
//.setMethodCount(3) // default 2
//.hideThreadInfo() // default shown
.setLogLevel(BuildConfig.LOGGER_LEVEL); // default LogLevel.FULL

但它不起作用:

Error:(31, 0) No such property: NONE for class: org.gradle.api.logging.LogLevel

FULL枚举值也是一样

谢谢你们的帮助!

最佳答案

您必须在属性类型和值中都包含包和类名:

buildTypes {
debug {
debuggable true
buildConfigField "com.orhanobut.logger.LogLevel", "LOGGER_LEVEL", "com.orhanobut.logger.LogLevel.FULL"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "com.orhanobut.logger.LogLevel", "LOGGER_LEVEL", "com.orhanobut.logger.LogLevel.NONE"
}
}

关于Android:如何从已知枚举中设置 gradle 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29780224/

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