Android Gradle 3.0.0-alpha2 插件,无法设置只读属性“outputFile"的值 [英] Android Gradle 3.0.0-alpha2 plugin, Cannot set the value of read-only property 'outputFile'

查看:25
本文介绍了Android Gradle 3.0.0-alpha2 插件,无法设置只读属性“outputFile"的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码

i was using this code

applicationVariants.all { variant -> 
    variant.outputs.each { output ->
        def SEP = "_"
        def flavor = variant.productFlavors[0].name
        def buildType = 
        variant.variantData.variantConfiguration.buildType.name
        def version = variant.versionName
        def date = new Date()
        def formattedDate = date.format('ddMMyy_HHmm')
        def newApkName = PROJECT_NAME + SEP + flavor + SEP + buildType + SEP + version + SEP + formattedDate + ".apk"
        def file = new File(newApkName)
        output.outputFile = file
    }
}


在构建新的 apk 时更改 apk 文件的名称,但由于我使用的是 Android Studio 3.0 Canary 2,出现此错误:
无法设置只读属性outputFile"的值....

推荐答案

As Android 插件 3.0 迁移指南 建议:

  • 使用all()代替each()
  • 如果您只更改文件名(这是您的情况),请使用 outputFileName 而不是 output.outputFile
  • 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"
    }
}

这篇关于Android Gradle 3.0.0-alpha2 插件,无法设置只读属性“outputFile"的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆