android {
// 创建 风味维度 添加
flavorDimensions('default')
//读取channel.txt 渠道文件 创建 flavor
file('channel.txt').readLines().each {
channel ->
productFlavors.create(channel, {
dimension "default"
manifestPlaceholders = [channel1: channel]
})
}
}
// 添加
AndroidManifest.xml
<application>
<meta-data
android:name="CHANNEL_VALUE"
android:value="${channel1}" />
</application>
// 打包出来获取方式
try {
val channel = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA).metaData.get("CHANNEL_VALUE")
showToast("------渠道包-----> $channel")
} catch (e: Exception) {
e.printStackTrace()
}
网友评论