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

Andrés Sandoval

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.

Andrés Sandoval

Written by

Android Engineer, writer, swimmer https://goo.gl/rDuuQw https://goo.gl/15GvfE

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade