Android: how to set gradle value from details list

I use Logger in my development, and I configure it in my Application class:

@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 is an enumeration (in the Logger library).

But I want to automatically set the log level according to my gradle build type; do something like this:

 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 } } 

then

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

But this does not work:

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

Same thing with the FULL enum value.

Thanks for the help guys!

+7
android gradle
source share
1 answer

You must specify the name of the package and class in both types and property values:

 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" } } 
+16
source share

All Articles