androidfluttergradlebuild

Flutter error when building for Android: Invalid <color> for given resource value


After changing the app icon with flutter_launcher_icons, I started having this issue after running flutter run and flutter build apk:

flutter build apk -debug

/Users/pitol/.gradle/caches/transforms-3/dfcbd5820ba82f60df3a20d93f4b43e6/transformed/core-1.8.0/res/values/values.xml:5:4: Invalid <color> for given resource value.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable
   > Resource compilation failed (Failed to compile values resource file /Users/pitol/workspace/3i/chat-bot/school_chat_bot_app/build/app/intermediates/incremental/release/mergeReleaseResources/merged.dir/values/values.xml. Cause: java.lang.IllegalStateException: Can not extract resource from com.android.aaptcompiler.ParsedResource@1f60c2b3.). Check logs for more details.

* 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 14s
Running Gradle task 'assembleRelease'...                           14.5s
Gradle task assembleRelease failed with exit code 1

The 'invalid given resourse' is this one: <color name="androidx_core_secondary_text_default_material_light">#8a000000</color>

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr format="reference" name="nestedScrollViewStyle"/>
    <color name="androidx_core_ripple_material_light">#1f000000</color>
    <color name="androidx_core_secondary_text_default_material_light">#8a000000</color>
    <color name="notification_action_color_filter">#ffffffff</color>
    <color name="notification_icon_bg_color">#ff9e9e9e</color>
    <dimen name="compat_button_inset_horizontal_material">4dp</dimen>

...

(It's a generated file located at /Users/pitol/.gradle/caches/transforms-3/dfcbd5820ba82f60df3a20d93f4b43e6/transformed/core-1.8.0/res/values/values.xml)

Tried to run flutter doctor -v, solved all the dependencies, updated android studio, updated Java and still get this error when I try to build android app (doctor -v command shows no error);

Already tried on Mac and Windows, and it shows the same error;

I also tried to create a new flutter project and builded succesfully, so the issue is in the project, not in the framework;


Solution

  • Step 1: Remove all the .png files generated by flutter_launcher_icons in the project;

    Step 2: Remove the flutter_launcher_icon implementation from pubspec.yaml;

    Step 3: Delete the .../android/app/src/main/res/values/colors.xml file;

    Step 4: Delete the .../android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml file;

    Step 5: Run flutter clean;

    Step 6: Run flutter pub get;

    Step 7: Make sure there are no dependencies for the platform desired by running flutter doctor -v;

    Step 8: Try to run or build the APK (flutter run or flutter build apk -debug);

    Step 9: If the app builds appropriately, you can try to import the flutter_launcher_icons again and follow their readme steps. But this time, keep the launcher icon file the same name as it is on their pubspec example;

    Step 10: Make sure the .xml files you deleted in previous steps weren't created again and run/build the app;