Android Studio升级到3.0的打包配置

以前在build.gradle文件中经常有这样的配置:

1.

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)
        }
    }
}
但是在Android Studio升级到最新版3.0之后,这段会报错,需要改成如下形式:

applicationVariants.all { variant ->
        variant.outputs.all { output ->

            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
                outputFileName = fileName
            }
        }
    }

(2018.1.24贴出我的维度设置)

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    defaultConfig {
        ...
        flavorDimensions "release"
    }
   
    productFlavors {
        
        tencent {
            dimension "release"
        }
    }
}

猜你喜欢

转载自blog.csdn.net/xlh1191860939/article/details/77933518