Execution failed for task ':app:cleanMergeDebugAssets' while running the app in flutter

Issue

Main error while running the app in Visual Studio Code v1.46.1

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:cleanMergeDebugAssets'.
> Unable to delete directory 'E:\ACNO\Flutter\jots_mobile\build\app\intermediates\merged_assets\debug\out'
    Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.
    - E:\ACNO\Flutter\jots_mobile\build\app\intermediates\merged_assets\debug\out\flutter_assets\assets
    - E:\ACNO\Flutter\jots_mobile\build\app\intermediates\merged_assets\debug\out\flutter_assets\packages\cupertino_icons
    - E:\ACNO\Flutter\jots_mobile\build\app\intermediates\merged_assets\debug\out\flutter_assets\packages
    - E:\ACNO\Flutter\jots_mobile\build\app\intermediates\merged_assets\debug\out\flutter_assets

* 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 50s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

This error gets resolved after flutter clean but even that shows the following error

Below is the output of flutter clean

Failed to remove build. A program may still be using a file in the directory or the directory itself. To find and stop such a program, see:
https://superuser.com/questions/1333118/cant-delete-empty-folder-because-it-is-used
Deleting build...                                                   19ms
Failed to remove E:\ACNO\Flutter\jots_mobile\.dart_tool. A program may still be using a file in the directory or the directory itself. To find and stop such a program, see:   
https://superuser.com/questions/1333118/cant-delete-empty-folder-because-it-is-used
Deleting .dart_tool...                                              21ms
Deleting Generated.xcconfig...                                       4ms
Deleting flutter_export_environment.sh...

Even when I kill the processes which are using build and .dart_tool folders as mentioned in this answer, flutter clean will show the same error

So, now I’ve to manually go to file explorer and delete the build & .dart_tool folders, which is the main issue here!

Summary: Main error while running the app gets resolved after flutter clean but even that is showing an error, so now I’ve to manually go and delete build & .dart_tool folders!

Q. How can I resolve these issues?

Update: Just noticed that this error occurs when I use "f5" to run my program in VS code and not when I use flutter run command in terminal or in Android Studio, but once it has occurred with "f5", it happens with flutter run command and Android Studio both. There is something wrong with the extension in VS Code that enables this "f5" shortcut, I guess!

Checkout these GitHub issues • flutter/flutterfwcd/vscode-kotlin

Solution

The problem was with the Kotlin plugin in VS Code, so removing it should fix our problem!

Now I able to run the project in debug mode. Below is my flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.17.4, on Microsoft Windows [Version 10.0.17763.1282, locale en-MY)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 4.0)
[√] VS Code (version 1.46.1)
[√] VS Code, 64-bit edition (version 1.46.1)
[√] Connected device (1 available)

I reinstall the Kotlin plugin in VS Code, the problem came back. I removed it, the project runs. So I guess its the plugin. The plugin I used and removed is Kotlin 0.2.17

Can anyone double-check whether the problem is because of this?

Answered By – Thiyraash David

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *