If you write a value in value, you will be able to fix only one channel per package, so change to the following way
<meta-data android:name="UMENG_CHANNEL" android:value="${UMENG_CHANNEL_VALUE}" />
Using placeholders, add the following code to the Build.gradle's Android tab to differentiate the channel information. This placeholder and the OGNL expression in the spring frame work a bit like
productFlavors{ huawei{ manifestPlaceholders = [UMENG_CHANNEL_VALUE: "huawei"] } xiaomi{ manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"] } }
Can be shortened to the following content
productFlavors{ huawei{ } xiaomi{ } } productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] }
If you want to include version information, you can modify it to the following configuration
productFlavors{ huawei{ } xiaomi{ } } productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith(‘.apk‘)) { def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk") output.outputFile = new File(outputFile.parent, fileName) } } }
The only way to get the channel information in the code is to easily send it to the server for data statistics.
private String getChannel() { try { PackageManager pm = getPackageManager(); ApplicationInfo appInfo = pm.getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); return appInfo.metaData.getString("UMENG_CHANNEL"); } catch (PackageManager.NameNotFoundException ignored) { } return "";}