Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=M

gradle打包的时候,自定义apk名称的时候,遇到这个问题:

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. Ope

搜到一个答案,解决了问题:


//**Use all() instead of each() 
//Use outputFileName instead of output.outputFile if you change only file name (that is your case)**

// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution.

android.applicationVariants.all { variant ->
                variant.outputs.all {
                    outputFileName = "xxx.apk"
                }
            }

答案出处:https://blog.csdn.net/CHITTY1993/article/details/78667069

 

我原来的方法是这样的:

 //修改生成的文件名
        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                def outputFile = output.outputFile
                def buildName
                variant.productFlavors.each { product ->
                    buildName = product.name
                }
                //这里修改文件名
                def fileName = "XXX" + "_" + buildName + "_" + variant.buildType.name + "_" +
                        "${defaultConfig.versionName}_${releaseDate()}.apk"
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值