AndroidStudios3.x遇到的坑

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"就可以了
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容