Robin Aegerter
Robin Aegerter

Reputation: 467

Flutter build failed for task ':app:mergeDebugResources'

At the moment I'm learning Flutter.

Today I ran into this error:

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

After searching for hours I already tried:

At the same time this error occurred I also had a new file in the android folder called settings_aar.gradle. I don't know if this has any relation to the error above or if it's something else.

The colors.xml mentioned in the error above looks like this:

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

After the error, flutter continues with building the packages I guess. The first few do succeed until a second error occurrs:

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

Again I have no idea if these two errors belong together.

My actual flutter version where I'm trying this is 1.17.5 flutter doctor -v looks like this:

[√] 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)

And this is my 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"

I know it's a pretty long question but I wanted to provide anything important. If anything else is required please tell me.

Thank you very much...

Upvotes: 4

Views: 13479

Answers (5)

Raj Kushwaha
Raj Kushwaha

Reputation: 1

Flutter build failed for task ':app:mergeDebugResources'

There is no the only one way is getting the same error on multiple and different mistakes So I explained what I did a mistake I hope it will help mistake I did

so you have to make a folder name assets or else but not under ❌src/main/res

Do like this click on the image given link(correct way) Like this correct way

and then try to add some images then update path resource and pub.yaml file images path where ever you used in code now run

flutter clean

and then

flutter pub get

Upvotes: 0

Aterus
Aterus

Reputation: 555

I got a similar problem with :app:mergeDebugResources on my Flutter app while working with flavors. The flavor, which caused the error, had a empty provider_path.xml file. The file is located at ../android/app/src/[FLAVORNAME]/res/xml/provider_path.xml The working flavor's provider_path.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path name="external_files" path="." />
</paths>

I simply copied the code in the empty file, run flutter clean and flutter pub get and the build succeeded without any error.

Upvotes: 0

flutterdemon
flutterdemon

Reputation: 1

Got this error when i used adaptive_icon_background: "ffffff" instead of adaptive_icon_background: "#ffffff" on pubspec.yaml file, hope it helps to someone facing this challenge.

Upvotes: 0

Robin Aegerter
Robin Aegerter

Reputation: 467

Okay. Figured it out.

  1. Updated the package flutter_launcher_icons to version ^0.7.5

  2. Removed all icons in all drawable and mipmap folders. Also deleted colors.xml.

  3. In pubspec.yaml replace the jpg launcher icon on android with a png.

  4. Recreate the icons with the command flutter pub run flutter_launcher_icons:main

  5. Clean the project and run again

Did now compile/build without any errors.

Good luck!

Upvotes: 5

Captivity
Captivity

Reputation: 338

You must try the flutter clean command. That should help fix the problem.

Upvotes: 3

Related Questions