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

两盒软妹~` 提交于 2020-12-06 06:51:27

问题


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

I am tyring to dispay image 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 probelem occers 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!

回答1:


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.

Blockquote

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




回答2:


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




回答3:


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.




回答4:


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




回答5:


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


来源:https://stackoverflow.com/questions/59910853/how-to-solve-flutter-error-os-error-access-denied-errno-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!