1.在path中加入studio安装目录下gradle的bin的路径
2.在module(项目)下的build.gradle修改红色代码并加入绿色代码
andrdoi{
…..
signingConfigs {
release {
storeFile file(“../xxxxx.keystore”)//签名路径,可以相对
storePassword “公钥”
keyAlias “别名”
keyPassword “秘钥”
}
}
…..
productFlavors {
channel {
manifestPlaceholders = [ channel:”placeholder” ]
}
}
channels()
}
// 多渠道打包,与android{}处在同级
def channels() {
if (project.hasProperty(“channel”)) {
// 渠道号配置文件路径
def path = “./build-types/channels.txt”
file(path).eachLine { line ->
if(!line.startsWith(“//”)){ //剔除注释行
android.buildTypes.create(line, {
manifestPlaceholders = [ channel:line ]
//带签名
signingConfig android.buildTypes.release.signingConfig
minifyEnabled android.buildTypes.release.minifyEnabled
proguardFiles android.buildTypes.release.proguardFiles
})
}
}
}
}
3.在androidmanifest.xml文件中加入
4.在工程app目录下新建build-types文件夹,并建立channels.txt
5.其中channels.txt用于写渠道号,并且一个渠道一行,不能有空行,否则打包会出错。
6.同步gradle,即点工具栏中的红圈图标,看工程是否有错。
7.运行dos,进入到工程下,即步骤4中的APP目录,执行gradle build -Pchannel命令。打包开始,初始打包会下载一些文件,耐心等待。如果出现BUILD SUCCESSFUL说明打包成功
8.最后在工程下,…../app/build/outputs/apk目录即可查看打包的apk。其中带unaligned是中间产物。
注:参看了博客http://blog.youkuaiyun.com/tu_bingbing/article/details/42362619 。并修正了其中的错误。