无法为ApkVariantOutputImpl_Decorated设置只读属性'outputFile'的值

无法为ApkVariantOutputImpl_Decorated设置只读属性'outputFile'的值

问题描述:

我在gradle脚本中使用以下代码来重命名由AndroidStudio生成的apk:

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)
    }
}

因此它正在生成名称如下的APK: 345-app-release.apk ,其中345是versionCode.

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

但是更新到AndroidStudio 3.0后,它会返回以下错误:

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

无法为以下项设置只读属性'outputFile'的值 ApkVariantOutputImpl_Decorated {apkData = Main {type = MAIN,fullName = debug, 过滤器= []}}的类型 com.android.build.gradle.internal.api.ApkVariantOutputImpl.

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.

使用output.outputFileName代替output.outputFile