装载:https://blog.youkuaiyun.com/ctianju/article/details/117668947
背景
网上的很多打包方式已经过时,会报错,Gradle sync failed: Cannot set the value of read-only property ‘outputFile’
比如类似这样的:
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = "SecyrityPassDemo_${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
解决
each()替换为all()
output.outputFile替换为outputFileName 即可
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName if (variant.buildType.name.equals('release')) {
fileName = "App_${android.defaultConfig.versionName.apk"
} else {
fileName = "App_${android.defaultConfig.versionName}_debug.apk"
}
outputFileName = fileName
}
}
}