Android开发Gradle之打多渠道包

打包配置:https://www.jianshu.com/p/afdaba526d33
AndroidManifest.xml 里设置动态渠道变量


在 build.gradle 设置 productFlavors , 这里假定我们需要打包的渠道为360、百度。

android {  
    ...
    productFlavors {
        qh360 {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "qh360"]
        }
        baidu {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
        }
       
    } 
  ...
}

或者批量修改

android {  

    productFlavors {
        qh360 {}
        baidu {}
    }  

    productFlavors.all { 
        flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] 
    }
}

android stuido 3.0新增:在app/gradle文件中加上 flavorDimensions 'versionCode' 否则会报错All flavors must now belong to a named flavor dimension。

android {
  ...
  flavorDimensions 'versionCode'
  ...
}
    productFlavors {

        qh360 {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
            dimension "channel"
        }
        baidu {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
            dimension "channel"
        }

    }
打包APK
生成的APK

你可能感兴趣的:(Android开发Gradle之打多渠道包)