1. 程式人生 > >Android Studio升級到3.0的打包配置

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" } }
}