Android项目APK打包And多渠道打包

1.清单文件配置
      
                    android:name="UMENG_APPKEY"
            android:value="59dc7855717c194e13000309">
  //Umeng创建应用的appKey
                    android:name="UMENG_CHANNEL"
            android:value="${CHANNEL_VALUE}" />
2.app下gradle文件 android方法里
    //添加如下代码
    productFlavors.all { flavors ->
        flavors.manifestPlaceholders = [CHANNEL_VALUE: name]
    }

    //修改生成的apk名字
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def oldFile = output.outputFile
            def newName = '';
            if (variant.buildType.name.equals('release')) {
                println(variant.productFlavors[0].name)
                def releaseApkName = 'bw-android-v' + defaultConfig.versionName + '-' + variant.productFlavors[0].name + '-sign-xtc.apk'
                output.outputFile = new File(oldFile.parent, releaseApkName)
            }
            if (variant.buildType.name.equals('beta')) {
                newName = oldFile.name.replace(".apk", "-v" + defaultConfig.versionName + "-build" + getDate() + ".apk")
                output.outputFile = new File(oldFile.parent, newName)
            }
            if (variant.buildType.name.equals('debug')) {
                println(variant.productFlavors[0].name)
                def releaseApkName = 'yzxxzx-android-v' + defaultConfig.versionName + '-' + variant.productFlavors[0].name + '-debug-xtc.apk'
                output.outputFile = new File(oldFile.parent, releaseApkName)
            }
        }
    }
3.Android方法外
//友盟统计
allprojects {
    repositories {
        mavenCentral()
    }
}
4.导入依赖
    compile 'com.umeng.analytics:analytics:latest.integration'
    
   

你可能感兴趣的:(Android项目APK打包And多渠道打包)