Android Studio 配置輸出apk的名字

一、在項目app下的build.gradle中的android標籤中作以下配置:

android.applicationVariants.all { variant ->android

        variant.outputs.each { output ->app

                def outputFile = output.outputFilegradle

                if (outputFile != null && outputFile.name.endsWith('.apk')) {ui

                    // 這裏修改apk名稱spa

                    def fileName = outputFile.name.replace("app", "xxoo_${defaultConfig.versionName}.${defaultConfig.versionCode}_${releaseTime()}")get

                    output.outputFile = new File(outputFile.parent, fileName)it

                }io

        }配置

}file

二、在項目app下的build.gradle中的android標籤中作以下配置,若是碰到如下錯誤:

Cannot set the value of read-only property 'outputFile’….

 

參考文章:https://stackoverflow.com/questions/44239235/android-gradle-3-0-0-alpha2-plugin-cannot-set-the-value-of-read-only-property

 

請嘗試下邊的操做方式:

android.applicationVariants.all { variant ->

        variant.outputs.all { output ->

                def outputFile = output.outputFile

                if (outputFile != null && outputFile.name.endsWith('.apk')) {

                    // 這裏修改apk名稱

                    def fileName = outputFile.name.replace("app", "xxoo_${defaultConfig.versionName}.${defaultConfig.versionCode}_${releaseTime()}")

                    outputFileName = new File(outputFile.parent, fileName)

                }

        }

}

相關文章
相關標籤/搜索