android - Gradle 版本 4.6 - 设置输出文件名时不支持绝对路径

标签 android gradle android-gradle-plugin

我是 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 ,但我无法理解该问题的答案。

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

最佳答案

它与更高版本的 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 是(或已经成为)只读属性。

关于android - Gradle 版本 4.6 - 设置输出文件名时不支持绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52523902/

相关文章:

java - 与EditText冲突: Watcher to the View + Observer to the MutableLiveData

java - 使用 gradle 从 cucumber 测试中获取 jacoco 报告

Android Studio Gradle 构建问题(无法运行项目)

java - Android项目中的Gradle错误

gradle - 带有 Kotlin DSL 的 Android 子项目

android - networkimageview 在离线模式下显示图像?杀死应用程序并重新打开后。就像 Facebook 应用程序一样

android - 图像在回收站 View 中重复

java - Yelp API Android 集成

java - Gradle绝对/相对路径

android - 没有可用于离线模式的缓存版本