在Android 升級(jí)到3.0后废菱,在打開(kāi)項(xiàng)目時(shí)按照提示升級(jí)Gradle 插件升級(jí)后咖刃,在重新編譯項(xiàng)目后差油,gradle 文件會(huì)報(bào)錯(cuò)汁展。有過(guò)這樣的經(jīng)驗(yàn)后,每次報(bào)錯(cuò)時(shí)自己都知道是哪個(gè)問(wèn)題厌殉,但是具體更改的內(nèi)容自己總是記不住,所以記錄下來(lái)侈咕,加深理解和記憶公罕。
# 一
- 報(bào)錯(cuò)內(nèi)容
Error:All flavors must now belong to a named flavor dimension.
- 解決方案
flavorDimensions "color"
productFlavors{
dev {
....
dimension "color"
.....
}
prod {
....
dimension "color"
....
}
}
# 二
- 報(bào)錯(cuò)內(nèi)容
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated
- 解決方案
使用 all() 替換 each()
使用 outputFileName 替換 output.outputFile
原內(nèi)容
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
def fileName = "new_app_phone_${defaultConfig.versionName}_${defaultConfig.versionCode}_release.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
修改后內(nèi)容
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "new_app_phone_${defaultConfig.versionName}_${defaultConfig.versionCode}_release.apk"
}
}