Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated

I was using the following code in my gradle script to rename the apks generated with AndroidStudio:

applicationVariants.all { variant ->     variant.outputs.each { output ->         output.outputFile = new File(output.outputFile.parent, defaultConfig.versionCode + "_" + output.outputFile.name)     } } 

So it was generating apks with names like: 345-app-release.apk, where 345 is the versionCode.

But after updating to AndroidStudio 3.0 it returns the following error:

Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

How can I achieve a similar renaming with the new build tools.

like image 936
Addev Avatar asked Oct 26 '17 08:10

Addev


2 Answers

Use output.outputFileName instead of output.outputFile

like image 76
AndrzejSc Avatar answered Nov 11 '22 15:11

AndrzejSc


2019 - Simple Solution for Gradle 3.0+** and 3.1.0

To change the name of the APK in Android

 android { //add inside the android {}    ......    applicationVariants.all { variant ->        variant.outputs.all {            def flavor = variant.name            def versionName = variant.versionName            outputFileName = "prefix_${flavor}_${versionName}.apk"        }    } } 

prefix_release_1.0.1.apk

like image 36
Zumry Mohamed Avatar answered Nov 11 '22 14:11

Zumry Mohamed