You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Target debug_android_application failed: FileSystemException: Cannot copy file to <elided>, path = <elided> (OS Error: Cannot create a file when that file already exists. #74227
I have an issue with flutter giving out semi-random errors on a larger project when I am performing flutter run. When I run the flutter clean the error went away for the first build, but any consecutive after that gave out an error on part of the gradle process. It happens like this like clock-work, every single time.
So I did some digging into the error, and what I found is that it's related to the flutter.bat with the ampersand exit. I don't know why, or how (judging from the big wall of text, people put some thought into the chaining) but truth be told when I move the exit /b part onto a separate line the error stopped occurring and I was able to perform flutter run consecutively without any errors!
This was the error description I was given:
FAILURE: Build failed with an exception.
* Where:
Script 'D:\SDK\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 904
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\SDK\flutter\bin\flutter.bat'' finished with non-zero exit value 1
Contents of the flutter.bat
REM To debug the tool, you can uncomment the following lines to enable checked mode and set an observatory port:
REM SET FLUTTER_TOOL_ARGS="--enable-asserts %FLUTTER_TOOL_ARGS%"
REM Chaining the call to 'dart' and 'exit' with an ampersand ensures that
REM Windows reads both commands into memory once before executing them. This
REM avoids nasty errors that may otherwise occur when the dart command (e.g. as
REM part of 'flutter upgrade') modifies this batch script while it is executing.
REM
REM Do not use the CALL command in the next line to execute Dart. CALL causes
REM Windows to re-read the line from disk after the CALL command has finished
REM regardless of the ampersand chain.
"%dart%" --disable-dart-dev --packages="%flutter_tools_dir%\.packages" %FLUTTER_TOOL_ARGS% "%snapshot_path%" %* & exit /B !ERRORLEVEL!
When I change the last line into this flutter run started to work.
I am not quite sure what makes my fix actually work or not work, but I assumed there might be some quirks in cmd.exe that maybe windows not only caches both commands but also cached error level instead of delay evaluating it. Can I safely use this fix or is there some idea on a more proper fix?
When I change the last line into this flutter run started to work.
We don't expect you to modify Flutter tool files by yourself!
Can you please revert the changes you made and then provide the output of flutter doctor -v, your flutter run --verbose and your pubspec.yaml.
Thank you
We don't expect you to modify Flutter tool files by yourself!
Young padawan, much learn you have to. No in all seriousness, I totally agree.
Here's the flutter doctor output, note it says flutter plugins are missing because the android studio changes folder layouts, flutter does in fact just work normally.
logs
PS D:\Visual Studio 2015\Projects\Best-Flutter-UI-Templates\best_flutter_ui_templates> flutter doctor -v
[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.18362.1256], locale en-US)
• Flutter version 1.22.5 at D:\SDK\flutter
• Framework revision 7891006299 (6 weeks ago), 2020-12-10 11:54:40 -0800
• Engine revision ae90085a84
• Dart version 2.10.4
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at D:\SDK\android-sdk
• Platform android-29, build-tools 29.0.2
• ANDROID_HOME = D:\SDK\android-sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[!] Android Studio (version 4.1.0)
• Android Studio at C:\Program Files\Android\Android Studio
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] VS Code (version 1.52.1)
• VS Code at C:\Users\phpfr\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.18.1
[√] Connected device (1 available)
• SM G985F (mobile) • RR8N205HXVZ • android-arm64 • Android 11 (API 30)
Here's pubspec.yaml
name: best_flutter_ui_templates
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
font_awesome_flutter: ^8.8.1
smooth_star_rating: ^1.1.1
intl: ^0.15.8
barcode_widget: ^1.5.0
flutter_svg: ^0.18.0
url_launcher: ^5.7.10
async: ^2.4.2
flutter_screen_lock: ^1.2.6
local_auth: ^0.6.3+4
flutter_secure_storage: ^3.3.5
pull_to_refresh: ^1.6.3
flutter_datetime_picker: ^1.4.0
odoo_api: ^1.0.4
vibration: ^1.7.3
flutter_money_formatter: ^0.8.3
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/
- assets/design_course/
- assets/fitness_app/
- assets/hotel/
- assets/icons/
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
fonts:
- family: WorkSans
fonts:
- asset: assets/fonts/WorkSans-Regular.ttf
- asset: assets/fonts/WorkSans-Medium.ttf
weight: 500
- asset: assets/fonts/WorkSans-SemiBold.ttf
weight: 600
- asset: assets/fonts/WorkSans-Bold.ttf
weight: 700
- family: Roboto
fonts:
- asset: assets/fonts/Roboto-Bold.ttf
- asset: assets/fonts/Roboto-Regular.ttf
- asset: assets/fonts/Roboto-Medium.ttf
weight: 400
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
Here's flutter run --verbose (stdout) successfull invocation.
Hi @phr34k
Can you please provide flutter run --verbose with only the crash logs reported in your first comment? It is a little bit confusing to me all the different logs you provided above. If you are facing any different issue other than in the OP, please file a new issue!
Thank you
@pedromassango I did two runs, one was a success, and one that failed (so you have a comparison.
The first log is where the build actually succeeded. I run it right after reverting my changes, in an attempt to provide you the failed logs, but it succeeded instead.
The second and third log, I reproduced a failed build, they are part of the same run, but I captured stdout/stderr separately.
Basically, due to the length of the log, I had to pipe the output to a file in order to capture it fully. But apparently, piping only captured the stdout stream, and so I copied over stderr from the console. I provided you both parts of the log to give you the full log.
From what I can tell from the log (stderr) by glancing over it, there seems to be an error copying one of the assets over. Am I right to read that this right that error propagates into the build failing? If so, any thoughts on what can I actually do about it on my side?
The file in question is not actually changed
I don't have the file open in an editor or in windows explorer to my knowledge.
I've rebooted my machine a couple of times already, and the error sooner or later popping up consistently again.
So if the filehandle stays open with exclusive access, it's probably due to an orphaned process either from flutter or vscode or something else that doesn't play nice (thumbnail generation? windows indexing?).
changed the title [-]Build failed with an exception, script 'D:\SDK\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 904[/-][+]Target debug_android_application failed: FileSystemException: Cannot copy file to <elided>, path = <elided> (OS Error: Cannot create a file when that file already exists. [/+]on Jan 20, 2021
Considering the age of the issue and lack of any activity for an extended period (over a year), I am going ahead and closing this as stale.
@phr34k If by any chance, you see the same error using latest stable version of the framework, kindly file a new issue and provide any relevant information that you can.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
pedromassangocode commentedon Jan 19, 2021
Hi @phr34k
We don't expect you to modify Flutter tool files by yourself!
Can you please revert the changes you made and then provide the output of
flutter doctor -v, yourflutter run --verboseand yourpubspec.yaml.Thank you
phr34k commentedon Jan 19, 2021
Young padawan, much learn you have to. No in all seriousness, I totally agree.
Here's the flutter doctor output, note it says flutter plugins are missing because the android studio changes folder layouts, flutter does in fact just work normally.
logs
Here's pubspec.yaml
Here's
flutter run --verbose(stdout) successfull invocation.Here's flutter run (stderr) of an unsuccessful run.
And here's the stdout of an unsuccesfull run
pedromassangocode commentedon Jan 19, 2021
Hi @phr34k
Can you please provide
flutter run --verbosewith only the crash logs reported in your first comment? It is a little bit confusing to me all the different logs you provided above. If you are facing any different issue other than in the OP, please file a new issue!Thank you
phr34k commentedon Jan 20, 2021
@pedromassango I did two runs, one was a success, and one that failed (so you have a comparison.
Basically, due to the length of the log, I had to pipe the output to a file in order to capture it fully. But apparently, piping only captured the stdout stream, and so I copied over stderr from the console. I provided you both parts of the log to give you the full log.
From what I can tell from the log (stderr) by glancing over it, there seems to be an error copying one of the assets over. Am I right to read that this right that error propagates into the build failing? If so, any thoughts on what can I actually do about it on my side?
So if the filehandle stays open with exclusive access, it's probably due to an orphaned process either from flutter or vscode or something else that doesn't play nice (thumbnail generation? windows indexing?).
[-]Build failed with an exception, script 'D:\SDK\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 904[/-][+]Target debug_android_application failed: FileSystemException: Cannot copy file to <elided>, path = <elided> (OS Error: Cannot create a file when that file already exists. [/+]phr34k commentedon Feb 8, 2021
Any update on this problem? The build error is getting more and more disruptive the bigger of an application I am working on.
danagbemava-nc commentedon Oct 6, 2022
Considering the age of the issue and lack of any activity for an extended period (over a year), I am going ahead and closing this as stale.
@phr34k If by any chance, you see the same error using latest stable version of the framework, kindly file a new issue and provide any relevant information that you can.
github-actions commentedon Oct 20, 2022
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.