Cannot set the value of read-onl

2017-12-07  本文已影响29人  奈何心善

更新Android Studio 3.0之后,出现Cannot set the value of read-only property ‘outputFile’报错,也就是用来打包后重命名的gradle出现了问题

旧版本

AS 2.3时用的代码:

applicationVariants.all { variant ->

variant.outputs.each { output ->

def outputFile = output.outputFile

if (outputFile != null && outputFile.name.endsWith('.apk')) {

def fileName = "driver_${variant.productFlavors[0].name}_v${defaultConfig.versionName}.apk"

output.outputFile = new File(outputFile.parent, fileName)

}

}

}

修改之后:

flavorDimensions 'api'

productFlavors {

...

}

android.applicationVariants.all { variant ->

variant.outputs.all {

outputFileName = "driver_${variant.productFlavors[0].name}_v${variant.versionName}.apk"

}

}

关于flavorDimensions可查看官方文档

https://developer.android.google.cn/studio/build/build-variants.htm

参考资料

答案来源:https://stackoverflow.com/questions/44239235/android-gradle-3-0-0-alpha2-plugin-cannot-set-the-value-of-read-only-property

官方文档解析:https://developer.android.google.cn/studio/build/gradle-plugin-3-0-0-migration.html#variant_api

作者:混沌鸿蒙一老君

链接:http://www.jianshu.com/p/1d5d1e640832

來源:简书

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

上一篇下一篇

猜你喜欢

热点阅读