您的位置:首页 > 移动开发 > Android开发

Android Studio 3.0.0 修改打包命名

2018-02-24 15:48 405 查看
Android Studio 3.0.0 引入了com.android.tools.build:gradle:3.0.0 插件,API发生了改变

Plugin 3.0.0之前的打包命名修改

// 自定义APK安装包名
android.applicationVariants.all {
variant ->
variant.outputs.each {
output ->
if (buildType.name.equals("debug")) {
output.outputFile = new File(output.outputFile.parent,
"app-debug.apk")
}
if (buildType.name.equals("release")) {
output.outputFile = new File(output.outputFile.parent,
"app-release.apk")
}
}
}


现在修改为

// 自定义APK安装包名
android.applicationVariants.all {
variant ->
variant.outputs.all {
output ->
def outputFile = output.outputFile
if (outputFile.name.contains("debug")) {
outputFileName = new File("../debug/", "app-debug.apk")
}
}
}


plugin 3.0.0 新增了variant.outputs.all(Closure action)方法,测试时发现,variant.outputs.each(…)方法中找不到outputFileName ,只有variant.outputs.all(Closure action)才能找到outputFileName 变量

更多说明

插件迁移的更多说明

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: