compile 'com.umeng.analytics:analytics:latest.integration'
<application>
<meta-data android:name="UNENG_APPKEY" android:value="6738jdu93ujdi892idjiu9"/>
<meta-data android:name="UNENG_CHANNEL" android:value="${UNENG_CHANNEL_VALUE}"/>
</application>
public void initUMeng(){
MobclickAgent.setDebugMode(true);
MobcliceAgent.openActivityDurationTrack(false);
}
apply plugin: 'com.android.application'
android {
defaultConfig{
manifestPlaceholders=["UMENG_CHANNEL_VALUE":"imooc"]
}
signingConfigs{
debug{}
release{
storeFile file("youdu.jks")
storePassword "123456"
keyAlias "qndroid"
keyPassword "123456"
}
}
buildTypes{
release{
...
signingConfig signingConfigs.release
}
}
productFlavors{
imooc{
manifestPlaceholders=[UMENG_CHANNEL_VALUE:"imooc"]
}
googleplyer{
manifestPlaceholders=[UMENG_CHANNEL_VALUE:"googleplyer"]
}
baidu{
manifestPlaceholders=[UMENG_CHANNEL_VALUE:"baidu"]
}
productFlavors.all{
flavor->flavor.manifestPlaceholders =[UMENG_CHANNEL_VALUE:"baidu"]
}
}
}
buildTypes {
release {
...
//指定我们release包的输出文件名就是我们的渠道名字
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith(".apk")) {
def fileName = "${variant.productFlavors[0].name}" + ".apk"
output.outputFile = new File(outputFile.parent, fileName);
}
}
}
}
}
productFlavors{
imooc{
...
resValuse("strings","name","imooc")
}
googleplayer{
...
resValuse("strings","name","googleplayer")
}
baidu{
...
resValuse("strings","name","baidu")
}
}
flavors中也可以改变applicationIdsuffix等