Gradle自定義apk名稱報錯
- error:
Cannot set the value of read-only property 'outputFile
applicationVariants.all { variant ->
variant.outputs.each { output ->
def fileName = "${variant.versionName}_release.apk"
def outFile = output.outputFile
if (outFile != null && outFile.name.endsWith('.apk')) {
output.outputFile =newFile(outFile.parent, fileName)
}
}
outputFile變?yōu)橹蛔x,不能修改輸出的名稱所以報錯。修改為:
variant.outputs.all { output -> // each 改為 all
def fileName = "${variant.versionName}_release.apk"
def outFile = output.outputFile
if (outFile != null && outFile.name.endsWith('.apk')) {
output.outputFileName = fileName // output.outputFile 改為 outputFileName
}
}
把each修改為all,然后通過outputFileName修改生成apk的名稱。此外,AS 3.0后打包完,除了apk包文件,還會多一個 output.json 參數(shù)文件。
- error:
Absolute path are not supported when setting an output file name
將”outputFile.parent” 修改為相對路徑解決此問題,修改為 :
outputFileName = new File(“../../../release/”, fileName)
Gradle一些屬性不能用
- error:
could not get unknown property 'bundleRelease' for object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication
將bundleRelease修改為bundleReleaseAar
flavors報錯
- error:
Error:All flavors must now belong to a named flavor dimension. Learn more at...
原因就是使用了productFlavors分包,解決方法就是在build.gradle中的defaultConfig中添加一個flavorDimensions "1"就可以了