【问题标题】:Change outputfile using new 'outputs' property in 0.13.0使用 0.13.0 中的新“输出”属性更改输出文件
【发布时间】:2014-09-27 07:55:06
【问题描述】:

刚刚将我的 android 项目更新为最新的 android gradle 插件并更改了脚本,因为有一些不推荐使用的方法。但是,当我尝试构建项目时,我得到了argument type mismatch 错误。我在尝试更改outputfile 名称时发现有问题,以下是'build.gradle' 中脚本的一部分:

android.applicationVariants.all { variant ->

   def apkName = target;
   if (variant.buildType.name == "release") {
      apkName += "-RELEASE.apk";
   } else {
      apkName += "-DEBUG.apk"
   }

   // this is the line caused type mismatch error
   variant.outputs.outputFile = file("$project.buildDir/outputs/apk/" + apkName)
}

我尝试更改为 variant.outputs.outputFile = "$project.buildDir/outputs/apk/" + apkName 但它不起作用。

如何解决?

【问题讨论】:

    标签: android gradle


    【解决方案1】:

    参考我自己对同一问题here 的回答,您可以将脚本更改为如下内容:

    variant.outputs.each { output ->
        if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
            output.outputFile = file("${project.buildDir}/outputs/apk/" + apkName)
        }
    }
    

    【讨论】:

      【解决方案2】:

      您需要直接在变体上设置 outputFile 属性。

      variant.outputFile = file("$project.buildDir/outputs/apk/" + apkName)
      

      【讨论】:

      • 这个问题特别指出他使用了一个版本的 android gradle 插件,其中 variant.outputFile 已被弃用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-18
      • 2012-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-22
      相关资源
      最近更新 更多