Ali Reza
Ali Reza

Reputation: 57

How to solve flutter error (OS Error: Access Denied, errno = 5 )?

I am trying to learn Flutter. My problem is that when I run my flutter project for the first time it runs and installs successfully on the device, but if I disconnect the device and rerun the project it gives an error.

I am trying to display images in my app.

When I run flutter clean or flutter clean build or flutter clean cache and rerun the project it does not gives the error, then after disconnecting the device the problem occurs again. I searched google for hours but it did not help me. this the the error:

Target debug_android_application failed: FileSystemException: Cannot copy file to 'G:\Flutter 
   Projects\my_practice_7\build\app\intermediates\flutter\debug\flutter_assets\images\image.png', 
path = 'G:\Flutter Projects\my_practice_7\images\image.png' 
(OS Error: Access is denied. 
, errno = 5)
build failed.

FAILURE: Build failed with an exception.

* Where:
Script 'G:\Android\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 780

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.

flutter doctor -v

[√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.18362.476], locale en-GB)
  • Flutter version 1.12.13+hotfix.5 at G:\Android\flutter
  • Framework revision 27321ebbad (7 weeks ago), 2019-12-10 18:15:01 -0800
  • Engine revision 2994f7e1e6
  • Dart version 2.7.0


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
  • Android SDK at G:\Android\Sdk
  • Android NDK location not configured (optional; useful for native profiling support)
  • Platform android-29, build-tools 29.0.2
  • ANDROID_HOME = G:\Android\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)

[√] VS Code (version 1.41.1)
  • VS Code at C:\Users\HP\AppData\Local\Programs\Microsoft VS Code
  • Flutter extension version 3.7.1

[√] Connected device (1 available)
  • Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)

  • No issues found!

Upvotes: 2

Views: 12358

Answers (7)

Suresh Kumar
Suresh Kumar

Reputation: 1135

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

copy "G:\Flutter Projects\my_practice_7\images\image.png" "G:\Flutter Projects\my_practice_7\build\app\intermediates\flutter\debug\flutter_assets\images\image.png"

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

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

Upvotes: 0

Muhammed Ramadan
Muhammed Ramadan

Reputation: 37

I deleted the file from its current location and made a run to make flutter re-build the file again and it worked.

Upvotes: 0

Amede Angel Aulerien
Amede Angel Aulerien

Reputation: 398

In my case, it was my Avast antivirus blocking access.

I have allowed flutter to have access and it works.

Upvotes: 0

Pragati Singh
Pragati Singh

Reputation: 2523

Don't copy .packages over from one machine to another. (It should be in .gitignore if using git.)

Instead, run flutter packages get on the mac, and it will recreate .packages.

(Don't copy .flutter-plugins either.)

  1. Delete .packages
  2. Delete pubspec.lock
  3. Run below command shown in image enter image description here

Upvotes: 2

ManuPulido
ManuPulido

Reputation: 25

I disabled the ransomware shield that prevented the files to be accessed and it worked perfectly, but there must be a solution without putting your files at risk

Upvotes: 1

Badr Kouki
Badr Kouki

Reputation: 1

I copied the entire content of pubspec.lock and then deleted it.. After that I created new file in the same path with the same file name which is pubspec.lock and paste the content that I already copied.. run "flutter pub get" and it should absolutely work fine.

Upvotes: 0

Eddie.O
Eddie.O

Reputation: 1

Try to uninstall the app on the device or perform wipe data on the emulator then run the application. This worked for me

Upvotes: 0

Related Questions