i was using this code
applicationVariants.all { variant ->
variant.outputs.each { output ->
def SEP = "_"
def flavor = variant.productFlavors[0].name
def buildType =
variant.variantData.variantConfiguration.buildType.name
def version = variant.versionName
def date = new Date()
def formattedDate = date.format('ddMMyy_HHmm')
def newApkName = PROJECT_NAME + SEP + flavor + SEP + buildType + SEP + version + SEP + formattedDate + ".apk"
def file = new File(newApkName)
output.outputFile = file
}
}
to change the name of apk file when i build new apk, but since i use the Android Studio 3.0 Canary 2 this error appear:
Cannot set the value of read-only property 'outputFile'....
As Android plugin 3.0 migration guide suggests:
all()
instead of each()
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"
}
}
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With