[Android] Android Gradle 3.0.0 plugin, Cannot set the value of read-only property ‘outputFile’

Posted in :

升級新版 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”


As Android plugin 3.0 migration guide suggests:

  • Use all() instead of each()
  • Use outputFileName instead of output.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"
    }
}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *