Android Gradle 3.0.0-alpha2 plugin, Cannot set the value of read-only property 'outputFile'
As Android plugin 3.0 migration guide suggests:
- 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"
}
}
See below:
applicationVariants.all { variant ->
variant.outputs.all { output ->
def newApkName = applicationId + "-" + variant.versionName + "(" + variant.versionCode + ")" + ".apk";
outputFileName = new File("${project.projectDir}/../outputs/apks/" + variant.name, newApkName);
}
}
Below code is working for me on android studio canary 3.0.0-alpha3
android.applicationVariants.all {
variant.outputs.all {
def newApkName
newApkName = "APPLICATION_NAME-" + defaultConfig.versionName + "-" + defaultConfig.versionCode".apk"
outputFileName = newApkName;
}
}
This change the apk file name