App打包和測試的時候會設置不一樣的AppName,這裏在gradle中進行AppName的配置能夠避免在正式打包的時候修改文件中AppName的值,android
buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' debuggable false resValue "string","AppName","Turman" } debug { resValue "string","AppName","TurmanTest" } }
編譯以後能夠直接從resValue string中獲取。測試
一樣,經過這種配置也能夠在BuildConfig中設置一些開關變量,好比:gradle
buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' debuggable false buildConfigField "boolean", "OPEN_LOG", "false" } debug { buildConfigField "boolean", "OPEN_LOG", "true" } }
能夠在正式發佈時關閉日誌。ui
manifest中的一些配置也能夠實現編譯時動態配置:debug
<meta-data android:name="BaiduMobAd_EXCEPTION_LOG" android:value="${BAIDUMOBAD_EXCEPTION_LOG}"/> <meta-data android:name="BaiduMobAd_CHANNEL" android:value="${MTJ_CHANNEL_VALUE}"/> productFlavors { centaline {} baidu {} baidu_search {} qihu360 {} tencent {} xiaomi {} wandoujia {} huawei {} qihu360_pop {} qihu360_search {} szbus {} productFlavors.all { flavor -> flavor.manifestPlaceholders = [MTJ_CHANNEL_VALUE: name,BAIDUMOBAD_EXCEPTION_LOG:true] } }