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

原创 2018年04月17日 15:30:19

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)
            }
        }



Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated

遇到问题: Android Gradle 3.0.0-alpha2 plugin, Cannot set the value of read-only property 'outputFil...
  • u013758456
  • u013758456
  • 2017-09-11 11:36:30
  • 3543

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

问题描述:Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkD...
  • qq_17477507
  • qq_17477507
  • 2017-11-03 13:21:56
  • 546

android studio3.0 编译 Cannot set the value of read-only property 'outputFile' for apkVariantOutputImp

修改方式: 原build.gradle中: variant.outputs.each { output -> def outputFile = output.outputFile ...
  • yinianjian2017
  • yinianjian2017
  • 2017-12-12 14:54:51
  • 600

解决 Android studio gradle 的 read-only property 'jniFolders' 编译错误

Error:(73, 0) Cannot set the value of read-only property 'jniFolders' on  open file  因为 build....
  • shuai123456
  • shuai123456
  • 2016-04-25 12:31:18
  • 7151

android studio3.0升级问题记录

今天早上升级了android studio3.0升级稳定版,之后编译项目出现了一些问题,通过网上搜索解决了,以下把自己遇到的问题记录一下: 1.gradle打包,自定义apk名称代码报错(Canno...
  • daoxiaomianzi
  • daoxiaomianzi
  • 2017-10-27 14:46:54
  • 7398

Error:(45, 0) Cannot set the value of read-only property 'outputFile' for ...

详细报错: Error:(45, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImp...
  • sinat_35670989
  • sinat_35670989
  • 2018-01-18 15:23:06
  • 2266

Cannot set the value of read-only property 'outputFile'

更新Android Studio 3.0之后,出现Cannot set the value of read-only property ‘outputFile’报错,也就是用来打包后重命名的gradl...
  • u014300915
  • u014300915
  • 2017-10-26 16:25:49
  • 5831

“Cannot set the value of read-only property 'outputFile' for 。。。”解决

我们在升级Android Studio 3.0以上版本时,如果自定义打包apk名称编译时遇到Cannot set the value of read-only property 'outputFile...
  • u014343528
  • u014343528
  • 2018-03-07 16:25:44
  • 245

android studio3.0(二)Cannot set the value of read-only property 'outputFile'

解决“Cannot set the value of read-only property 'outputFile...'”的问题。
  • Builder_Taoge
  • Builder_Taoge
  • 2017-11-01 13:53:38
  • 3287
收藏助手
不良信息举报
您举报文章:Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=M
举报原因:
原因补充:

(最多只允许输入30个字)