Android Studio 3.0 - Fix apk naming issue when upgrading to Gradle 3.0.0

Android Studio error “Cannot set the value of read-only property ‘outputFile’ for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN……”’

To fix issue follow steps below:

YourApp/build.gradle

android.applicationVariants.all { variant ->

variant.outputs.each { output ->
def finalVersionCode = 10000 + versionCode
output.versionCodeOverride = finalVersionCode
output.outputFile = new File(
output.outputFile.parent, output.outputFile.name.replace(".apk","-${finalVersion}.apk"))
}
}
  1. Change ‘each’ to ‘all’
  2. Change ‘output.outputFile’ to ‘outputFileName
android.applicationVariants.all { variant ->

variant.outputs.all { output ->
def finalVersionCode = 10000 + versionCode
output.versionCodeOverride = finalVersionCode
outputFileName = new File(
output.outputFile.parent,
outputFileName.replace(".apk", "-${finalVersionCode}.apk"))
}
}

3. Run $./gradlew clean build

Done.