Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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/flutter • fwcd/vscode-kotlin

like image 941
Arshdeep Singh Avatar asked Jun 22 '20 02:06

Arshdeep Singh


4 Answers

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?

like image 180
Thiyraash David Avatar answered Oct 22 '22 13:10

Thiyraash David


Uninstalling the Kotlin 0.2.18 extension on VSCode worked for me. I didn't need to delete the build and .dart_tool files mentioned above.

like image 30
Danilo Rêgo Avatar answered Oct 22 '22 15:10

Danilo Rêgo


At the moment I solved using "sudo" mode.

sudo flutter run

I don't have installed Kotlin on VSCode. I hope to help something

like image 1
Fernando Piedra Avatar answered Oct 22 '22 15:10

Fernando Piedra


To resolve this, you have to forcefully delete your merged_assets folder and all of its content (i.e 'E:\ACNO\Flutter\jots_mobile\build\app\intermediates\merged_assets\debug\out') since Flutter isn't able to do that for you because one or two programs are using the folders at the background.

To delete the folder forcefully, you can download this exe file: https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer

Then, search for 'merged_assets' in the Find tab. Click on the applications using it and kill them (usually dart.exe and cmd.exe).

After this, run flutter clean Then re-run your app, it should work successfully.

like image 1
IdrisAde Avatar answered Oct 22 '22 13:10

IdrisAde