今天把Android studio 升到3.0以后,把原先的工程导入之后,出现Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.就是后来打包命名的gradle出现了问题
旧版本
AS 2.3.1的版本
android.applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('.apk')) { //这里修改apk文件名 def fileName = outputFile.name.replace("app", "doctor") output.outputFile = new File(outputFile.parent, fileName) } } }
新版本
AS 3.1.2
android.applicationVariants.all { variant -> variant.outputs.all { outputFileName = "doctor.apk" } }希望可以帮助到大家