Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=M


Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type Ope


//**Use all() instead of each() 
//Use outputFileName instead of output.outputFile if you change only file name (that is your case)**

// 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 = "xxx.apk"




        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                def outputFile = output.outputFile
                def buildName
                variant.productFlavors.each { product ->
                    buildName =
                def fileName = "XXX" + "_" + buildName + "_" + + "_" +
                output.outputFile = new File(outputFile.parent, fileName)