美文网首页
AndroidStudios3.x遇到的坑

AndroidStudios3.x遇到的坑

作者: MIRROR1217 | 来源:发表于2018-12-14 10:21 被阅读0次

    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变为只读,不能修改输出的名称所以报错。修改为:

        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 参数文件。

    • 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"就可以了

    相关文章

      网友评论

          本文标题:AndroidStudios3.x遇到的坑

          本文链接:https://www.haomeiwen.com/subject/kwuwhqtx.html