任务':app:mergeDebugResources'的Flutter构建失败

Posted

技术标签:

【中文标题】任务\':app:mergeDebugResources\'的Flutter构建失败【英文标题】:Flutter build failed for task ':app:mergeDebugResources'任务':app:mergeDebugResources'的Flutter构建失败 【发布时间】:2020-11-23 11:59:52 【问题描述】:

目前我正在学习 Flutter。

今天我遇到了这个错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource compilation failed
     C:\Users\USERNAME\Documents\Flutter\my-app\android\app\src\main\res\values\colors.xml:3:5-78: AAPT: error: invalid color.

     C:\Users\USERNAME\Documents\Flutter\my-app\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml: AAPT: error: file failed to compile.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 23s

搜索了几个小时后我已经尝试过:

其他 gradle 版本 其他launcher_icon 有或没有 settings_aar.gradle

发生此错误的同时,我在android 文件夹中还有一个名为settings_aar.gradle 的新文件。我不知道这是否与上面的错误有任何关系,还是其他原因。

上面错误中提到的colors.xml看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="ic_launcher_background">lib/assets/launcher/logo.png</color>
</resources>

错误之后,颤振继续构建我猜的包。前几个确实成功,直到发生第二个错误:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve com.github.droibit.customtabslauncher:launcher:1.4.0.
     Required by:
         project :app > com.github.droibit.plugins.flutter.customtabs:flutter_custom_tabs_release:1.0
      > Could not resolve com.github.droibit.customtabslauncher:launcher:1.4.0.
         > Could not get resource 'https://jcenter.bintray.com/com/github/droibit/customtabslauncher/launcher/1.4.0/launcher-1.4.0.pom'.
            > Could not HEAD 'https://repo.jfrog.org/artifactory/libs-release-bintray/com/github/droibit/customtabslauncher/launcher/1.4.0/launcher-1.4.0.pom?referrer'.
               > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 9s

同样,我不知道这两个错误是否属于一起。

我正在尝试的实际颤振版本是1.17.5 flutter doctor -v 看起来像这样:

[√] Flutter (Channel unknown, v1.17.5, on Microsoft Windows [Version 10.0.18363.900], locale de-CH)
    • Flutter version 1.17.5 at C:\Users\USERNAME\flutter
    • Framework revision 8af6b2f038 (5 weeks ago), 2020-06-30 12:53:55 -0700
    • Engine revision ee76268252
    • Dart version 2.8.4


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at C:\Users\USERNAME\sdk
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = C:\Users\USERNAME\sdk
    • ANDROID_SDK_ROOT = C:\Users\USERNAME\sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    • All Android licenses accepted.

[√] Android Studio (version 3.5)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[!] IntelliJ IDEA Ultimate Edition (version 2019.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2019.1.3
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

[√] VS Code (version 1.47.3)
    • VS Code at C:\Users\USERNAME\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.13.1

[√] Connected device (1 available)
    • AOSP on IA Emulator • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

这是我的 pubspec.yaml:

name: MyApp
description: Some description

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  
  
  cupertino_icons: ^0.1.3
  http: ^0.12.2
  flutter_html_view: ^0.5.12
  url_launcher: ^5.5.0
  flutter_slidable: ^0.5.5
  add_2_calendar: ^1.4.0
  flutter_launcher_icons: ^0.7.5
  onesignal_flutter: ^2.6.0
  flutter_staggered_grid_view: ^0.3.2
  
dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  assets:
    - lib/assets/logo.jpg
    - lib/assets/logo.png


flutter_icons:
  ios: true
  android: true
  image_path_ios: "lib/assets/launcher/logo.jpg"
  image_path_android: "lib/assets/launcher/logo.png"
  adaptive_icon_background: "lib/assets/launcher/logo.png"
  adaptive_icon_foreground: "lib/assets/launcher/logo.png"

我知道这是一个很长的问题,但我想提供任何重要的东西。如果还有什么需要请告诉我。

非常感谢...

【问题讨论】:

【参考方案1】:

好的。想通了。

    将包flutter_launcher_icons更新为版本^0.7.5

    删除了所有可绘制和 mipmap 文件夹中的所有图标。也删除了colors.xml。

    pubspec.yaml 中,用 png 替换 android 上的 jpg 启动器图标。

    使用命令flutter pub run flutter_launcher_icons:main重新创建图标

    清理项目并再次运行

现在编译/构建没有任何错误。

祝你好运!

【讨论】:

【参考方案2】:

您必须尝试flutter clean 命令。这应该有助于解决问题。

【讨论】:

这没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方留下评论。 - From Review 已经尝试了几次,还flutter pub cache repair。没用。

以上是关于任务':app:mergeDebugResources'的Flutter构建失败的主要内容,如果未能解决你的问题,请参考以下文章

任务 ':app:mergeDebugResources' 的 Jenkins 执行失败,找不到文件

任务 'app:mergeDebugResources' Crunching Cruncher 执行失败....png 失败

Android Studio - 无法构建“任务':app:mergeDebugResources'的执行失败。”

错误:任务应用程序执行失败:mergeDebugResources

任务 ':app:mergeDebugResources' 执行失败。 > java.util.concurrent.ExecutionException:com.android.builder

无法处理文件 - Android Studio (app:mergeDebugResources)