def static releasetime() { return new date().format("yyyymmdd", timezone.gettimezone("utc")) }
android { compilesdkversion 26 buildtoolsversion "26.0.0" defaultconfig { applicationid "com.jason.log.text" minsdkversion 21 targetsdkversion 26 versioncode 1 versionname "1.0".concat("_").concat(releasetime())//版本号加上时间 testinstrumentationrunner "android.support.test.runner.androidjunitrunner" }
android { ... buildtypes { debug { minifyenabled false buildconfigfield "boolean", "log_debug", "false" //定义变量,区分debug 或release 状态,可直接在代码中buildconfig.log_debug使用,便于添加调试log } release { //签名 minifyenabled false buildconfigfield "boolean", "log_debug", "true" proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } applicationvariants.all { variant -> variant.outputs.each { output -> def outputfile = output.outputfile if (outputfile != null && outputfile.name.endswith('.apk')) { def type = "" if (variant.buildtype.name == 'debug') { type = "_debug" } def filename = "logtest_v${defaultconfig.versionname}${type}.apk" //定义apk名 output.outputfile = new file(outputfile.parent, filename) } } } } }
另外,我们可以在debug或release 标签中定义一个变量,用于控制是否输出调试log,如下:
buildconfig.log_debug在debug状态为true,release 状态下为false
if(buildconfig.log_debug){ log.d(tag,"...."); }
如对本文有疑问, 点击进行留言回复!!
Android SDK Manager 不知为什么突然打不开了?看这里
监听Android系统发出的插入SD卡并且已正确安装(识别)时发出的广播
RecyclerView三种常用效果的实现方法-android-kotlin
Android Studio app启动错误 Error running :Default Activity not found
网友评论