Cannot set the value of read-only property 'outputFile'多渠道打包
阿新 • • 發佈:2018-11-16
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. Open File
更新AS 3.0之後,出現Cannot set the value of read-only property ‘outputFile’報錯,查詢了文件才知道是用來打包後重命名的gradle出現了問題。
原來的打包名設定如下
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith(‘.apk’)) {
output.outputFile = new File(outputFile.parent, “card.io-sample-app-${variant.name}.apk”)
}
}
}
修改為如下:
flavorDimensions ‘api’
productFlavors {
/渠道打包相關設定
}
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = “driver_ {variant.versionName}.apk”
}
}
關於flavorDimensions可檢視官方文件
https://developer.android.google.cn/studio/build/build-variants.htm
彼此交流,補充填坑,希望對你有所幫助。紙上得來終覺淺,書到用時方恨少。