android {
......
productFlavors{
demo {
applicationId = "com.example.demo"
}
}
android.applicationVariants.all { variant ->
variant.outputs[0].processManifest.doLast {
def nam = variant.productFlavors[0].name
def taskname = variant.name
println '=====productFlavors====='+nam + ' ,task:'+taskname
// "demo"是渠道隐藏启动图标
if ("demo".equalsIgnoreCase(nam) && taskname.contains("Release")) {
String manifestPath = variant.outputs[0].processResources.manifestFile
println "=====remove launcher icon=====$manifestPath"
def manifestContent = file(manifestPath).getText()
println '=====read manifest string====='+manifestContent
//<intent-filter>
//<action android:name="android.intent.action.MAIN" />
//<category android:name="android.intent.category.LAUNCHER" />
//</intent-filter>
//移除LAUNCHER 标记的activity,则没有启动图标
manifestContent = manifestContent.replace('LAUNCHER', 'DEFAULT')
println '=====write manifest string====='+manifestContent
new File(manifestPath).write(manifestContent)
}
}//doLast
}//all
}
|