【问题标题】:Gradle Version 4.6 - Absolute path are not supported when setting an output file nameGradle 版本 4.6 - 设置输出文件名时不支持绝对路径
【发布时间】:2018-09-26 18:16:13
【问题描述】:

我是 Android 新手。因此,作为我学习的一部分,我按照本教程制作了一个图标包 - https://blog.prototypr.io/how-to-create-an-android-icon-pack-app-ecb77811b938

当我将项目导入 Android Studio 时,出现以下错误 - Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated 我解决了这个错误,因为那里已经提到了答案。之后,当我尝试构建项目时,出现以下错误 - 设置输出文件名时不支持绝对路径。

当我在 Android Studio 中打开该文件时,它显示错误发生在以下代码中:

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        output.outputFileName = new File(
                output.outputFile.parent, "MyIconPack-${variant.versionName}.apk")
    }
}

所以我再次在这里搜索并找到了这个 - android studio 3.1: build:gradle:3.1.0 - Absolute path are not supported when setting an output file name,但我无法理解该问题的答案。

所以请帮我解决这个错误。

【问题讨论】:

  • 问题标题与提供的示例代码不符。

标签: android gradle android-gradle-plugin


【解决方案1】:

它与更高版本的 Gradle 类似:

android.applicationVariants.all { variant ->
    variant.outputs.all { output ->
        def fileName = "${project.name}_${output.baseName}-${variant.versionName}.apk"
        outputFileName = new File(output.outputFile.parent, fileName).getName()
    }
}

因为output.outputFileName 是(或已经成为)只读属性。

【讨论】:

  • 它给出了新的错误,因为无法为 com.android.build.gradle.internal.api.ApplicationVariantImpl 类型的对象设置未知属性“outputFileName”。
  • @VatsalDesai 使用output.outputFileName 而不仅仅是outputFileName
猜你喜欢
  • 2019-04-11
  • 1970-01-01
  • 2016-06-29
  • 2011-12-17
  • 2021-11-24
  • 1970-01-01
  • 1970-01-01
  • 2016-05-12
  • 1970-01-01
相关资源
最近更新 更多