轉載請標明出處:http://www.javashuo.com/article/p-novprlwt-cd.htmlhtml
在作多渠道打包的時候出現了這個錯誤,在高版本的gradle出現。android
具體錯誤爲: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.
個人代碼爲下:api
這個在低版本的gradle是行得通的,可是高版本就不行。app
高版本的應該這樣:gradle
buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro' applicationVariants.all { variant -> variant.outputs.all { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('.apk')) { def fileName = "novel_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk" outputFileName = fileName } } } } }
將variant.outputs.each改成variant.outputs.allui
將output.outputFile = new File(outputFile.parent, fileName)改成outputFileName = fileNamespa