Main application position: Use the flag bit to change when a view is displayed, or leave some functions temporarily but not display, and you can also use the flag bit to distinguish whether to display. Can also be used to get String settings.
-
Add global flags in config.gradle
such as:conf = [ is_market:true, is_show:false ]
2. Use buildConfigField in build.gradle in a module to get and store values
Such as
defaultConfig {
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
//add flag upload to app market by lhw
buildConfigField "Boolean", "IS_UPLOAD_APP_MARKET", "${rootProject.ext.conf.is_upload_app_market}"//这里就是将cofig的值获取
buildConfigField "Boolean", "IS_SHOW_MINICHAT", "${rootProject.ext.conf.is_show_minichat}"//这里就是将cofig的值获取
// testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
3. Introduce BuildConfig where you need to call to get the value,
import com.mo.damiframework.BuildConfig; //Import module
if (!BuildConfig.IS_UPLOAD_APP_MARKET){ //依据值判断
llt_guard_view.setVisibility(View.VISIBLE);
llt_binding_view.setVisibility(View.GONE);
}
Attachment: buildConfigField can store String
Such as
debug {
buildConfigField("boolean", "LOG_DEBUG", "true") //此处储存一个boolean
buildConfigField "String", "SERVER_HOST", "\"200.200.200.50/\"" //储存String
minifyEnabled true//true:启用混淆,false:不启用
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
shrinkResources false
zipAlignEnabled true
pseudoLocalesEnabled true
signingConfig signingConfigs.release
}
}
End