hyo
hyo

Reputation: 11

Error:(63, 0) Cannot set the value of read-only property 'outputFile'

I want your help. please i help.

Error:(63, 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. Open File

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def file = output.outputFile
        output.outputFile = new File(file.parent, "kickmaterial-" + defaultConfig.versionName + ".apk")
    }
}

android version is 3.0.1 please your help.

Upvotes: 0

Views: 2647

Answers (1)

ישו אוהב אותך
ישו אוהב אותך

Reputation: 29814

Start from gradle plugin 3.0, you can't use each() as in the documentation says:

Using the Variant API to manipulate variant outputs is broken with the new plugin. It still works for simple tasks, such as changing the APK name during build time, as shown below:

// 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"
    }
}

So, you need to make your block code like the following:

android.applicationVariants.all { variant ->
    variant.outputs.all {
        outputFileName = "$kickmaterial-${variant.versionName}.apk"
    }
}

Upvotes: 1

Related Questions