您的位置:首页 > 产品设计 > UI/UE

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

2018-03-04 20:01 671 查看
详细报错:
Error:(45, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=xiaomiDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
<a href="openFile:H:\CloudMus\app\build.gradle">Open File</a>

位置:
// 自定义输出配置
//            applicationVariants.all { variant ->
//                variant.outputs.each { output ->
//                    def outputFile = output.outputFile
//                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
//                        // 输出apk名称为great_v1.0_wandoujia.apk
//                        def fileName = "great${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
//                        output.outputFile = new File(outputFile.parent, fileName)
//                    }
//                }
//            }

Android plugin 3.0 建议使用
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 = "${variant.name}-${variant.versionName}.apk"
}
}
故而修改上面的写法:
applicationVariants.all { variant ->
variant.outputs.all {
// 输出apk名称为great_v1.0_wandoujia.apk
def fileName = "great${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
outputFileName = fileName

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android gradle outputFile
相关文章推荐