Build fails after 2 times build of the application in flutter

4.4k views Asked by At

After building my flutter application in VS code, I successfully run the app, everything works fine. But after 2 or more times of restart of the application, whenever I run my code again, the build gets failed. This is the error pops up.

Target debug_android_application failed: FileSystemException: Cannot copy file to 'J:\flutter_projects\webdoc\build\app\intermediates\flutter\debug\flutter_assets\assets\images\background.png', path = 'J:\flutter_projects\webdoc\assets\images\background.png' (OS Error: Access is denied.
, errno = 5)
build failed.

FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 780

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* 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
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                        10.2s
Gradle task assembleDebug failed with exit code 1

When first time this error has occured, I cut all the files from the current directory and copied into other directory, and then it works again fine. But even now after running 2 or 3 times again the error pops up. Is there any fix available to this problem?

I tried deleting the .vscode, rebuilding again, but still its the same!!

3

There are 3 answers

4
Khadga shrestha On

This problem can be solved by turning of Windows Controlled Folder AccessSteps to turn of windows cont

0
Suresh Kumar On

It seems to be a file permissions related issue. try to copy the files using command line. you shall receive similar error.

copy J:\flutter_projects\webdoc\assets\images\background.png J:\flutter_projects\webdoc\build\app\intermediates\flutter\debug\flutter_assets\assets\images\background.png

Now check if you have necessary permissions on the destination directory/file or the destination file/directory is not read only.

Blockquote

Reference : https://github.com/flutter/flutter/issues/49874

1
Om Trivedi On

Stop running your application clear all recents applications then try again.

If this do not work try unistall your application, reinstall applications.

If these also not works , run 'flutter clean' then 'flutter pub get' .

These will clear temp files and add only neccessary files.