详细报错:
Error:(45, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=xiaomiDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
<a href="openFile:H:\CloudMus\app\build.gradle">Open File</a>
位置:
// 自定义输出配置
// applicationVariants.all { variant ->
// variant.outputs.each { output ->
// def outputFile = output.outputFile
// if (outputFile != null && outputFile.name.endsWith('.apk')) {
// // 输出apk名称为great_v1.0_wandoujia.apk
// def fileName = "great${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
// output.outputFile = new File(outputFile.parent, fileName)
// }
// }
// }
Android plugin 3.0 建议使用
Use all() instead of each()
Use outputFileName instead of output.outputFile if you change only file name (that is your case)
例子:
// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution.
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.apk"
}
}
故而修改上面的写法:
applicationVariants.all { variant ->
variant.outputs.all {
// 输出apk名称为great_v1.0_wandoujia.apk
def fileName = "great${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
outputFileName = fileName
}
}