[Android] Android Gradle 3.0.0 plugin, Cannot set the value of read-only property ‘outputFile’
阿新 • • 發佈:2018-12-23
升級新版 Gadle 之後,舊的 Gradle 2.3 的修改 apk 檔名的方式不能繼續使用,需要調整成新的寫法,Error Message:
Error:(57, 0) 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. <a href=”openFile:/Users/max/Documents/git/LockCamera_Android/app/build.gradle”
- Use
all()
instead ofeach()
- Use
outputFileName
instead ofoutput.outputFile
if you change only file name (that is your case)
Example from the guide:
// 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" } }