版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhouxianling233/article/details/78360884
升级android studio3.0,gradle升级4.1,以前更改apk名字的方式报错:
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=release, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
以前是这样的
applicationVariants.all { variant ->
if (variant.buildType.name == "release") {
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// apk_渠道名-版本号-版本名称-编译时间.apk
def fileName = "zszy-${defaultConfig.versionCode}- v${defaultConfig.versionName}-${releaseTime()}.apk"
output.outputFile = new File(outputFile.getParent(),fileName)
//
}
}
}
}
现在我们需要将
output.outputFile = new File(outputFile.getParent(),fileName)
更改为
outputFileName = fileName
如下
applicationVariants.all { variant ->
if (variant.buildType.name == "release") {
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// apk_渠道名-版本号-版本名称-编译时间.apk
def fileName = "zszy-${defaultConfig.versionCode}-v${defaultConfig.versionName}-${releaseTime()}.apk"
outputFileName = fileName
}
}
}
}