Flutter failed to delete a directory at "build\flutter_assets" - flutter

I've never had this error. The error doesn't appear when I run "flutter run -d chrome" for the initial flutter example but when I add a couple of folders this error appears. thank you for the help
Flutter failed to delete a directory at "build\flutter_assets". The flutter tool cannot access the file or directory.
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.

The build folder is auto-generated when flutter runs. If you created the flutter_assets folder in the build folder, move it to the assets folder instead. (I mixed up the assets and flutter_assets folders in my head.)
I had this issue and wound up manually deleting the entire build folder and running flutter clean (see other suggestions here on SO and here on GitHub).

Related

Flutter run and clean error "Flutter failed to delete a directory" when project is in synced folder

Full error:
Flutter failed to delete a directory at "build\flutter_assets". The flutter tool cannot access the file or directory. Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
Error occurs when trying to run flutter run -d chrome with these notes (all on new freshly created projects):
If the project is located in C: drive - it works always
If the project is located in D: drive inside a synced D:\Google Drive\ folder, then it throws the error on 2nd run.
If the project is located in D: outside of the synced folder - it works always
However, I need it to run inside the synced folder, since I am using multiple locations and computer for development of a project.
Flutter 3.3.2 • channel stable. Only using for Chrome device (web dev). I am using Windows 10. Flutter installed on D:\src\flutter.
List of things I have tried:
Moving build folder contents to the assets folder instead. Result: runs once, but any additional runs throw the error again. As suggested here.
flutter clean Result: throws same error
Running flutter clean with cmd as an administrator. Result: same error
Deleting the folder manually. Result: complains about another folder with the same error. Once I manually delete all of the ones it complains about, it runs once, but any additional runs throw the error again.
Restarting computer
Even tried giving Everyone full-access permissions to the project folder.
Tried installing flutter in different location C:\src\flutter
I been trying to solve this for days and none of the answers I found on the internet work.
Flutter doctor output: https://pastebin.com/9XpHW7T8
EDIT: Tried a few more things and added them to the list.
EDIT2: Added another thing I tried.
EDIT3: Added flutter doctor output.

Weird output from "flutter clean" command when used outside folder that has build

When i run flutter clean a folder outside the main build folder. I this response:
Changing current working directory to: /User/..
Why is that? and what does working directory refer to? How do i know my old one?
There needs to be a yaml file for flutter clean to work correctly.
That was my mistake.

Could not create task ... this and base files have different roots

I've built an app with Android Studio and Flutter and wanted to generate a signed APK.
When I go to Tools->Flutter->Open Android module in Android Studio, it starts to build the project.
But after some time I get this Error and I don't know how to change the roots or what to do.
It seems like the problem are just two packages (url_launcher and shared preferences)
My Project is on my hard disk F:
and the flutter folder is on my hard disk C:
Error Message "Could not create task..."
Is this maybe because my project is on F: and the flutter folder with the packages in C: ?
How can I change the flutter folder to F: ?
I fixed mine by moving the project directory to the same drive. My project was stored in E:\ so, I moved it to C:.
My answer is almost the same as rvr93's answer but I did not add anything to the environment variables.
Create a directory in the same drive as your project and add PUB_CACHE environment variable. Run flutter pub get.
This worked for me.
I had your same issue, Gradle couldn't sync the android module, I solved it by deleting the android/ directory from the Flutter project, then recreate it using the command flutter create --platforms android .
Notice the "." at the end of the command it's part of it, it means create the Android project in the current directory.
As a workaround, you can do the following steps -
run flutter clean
do the Gradle sync without flutter pub get and make necessary changes to
native android code.
do pub get and run the app.
I have the same issue,
it seems the flutter project and the SDKs are in different prtitions of the hard disk
just go to the project root and run flutter clean
then go to the android folder and delete the .gradle folder
then back to the project root and run flutter pub get
and rebuild the app
As a workaround, you can do the following steps :
Open a terminal.
Run flutter clean.
Do the Gradle sync without flutter pub get and make necessary changes to native Android code or click on try again.
Do flutter pub get and run the app.
You will see that the SHA1 has been generated.
I faced the same issue in my android project after upgrading gradle.
My project was in my D drive, and I had set the destination folder for the generated apk in my desktop, which is in C drive. I changed the destination folder to a folder in D drive, and the issue got resolved.
I was facing the same issue all I did was to go build.gradle file in android folder and then change the following code as follows
dependencies {
//CHANGE THE Version in YOUR BUILD.GRADLE FILE
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
This is a temporary solution - track status here

Flutter: How to backup flutter project without build directory?

I want to make a complete backup of the Flutter project, and I noticed the build folder is the biggest one.
Size Details:
Total App Size: 889.6 MB
Build Directory: 743 MB
Remaining directories, including ios, android, assets and lib: 146 MB
I think, zipping project excluding build directory would be considered full backup and it will contain everything needed to start again.
Q. Is that correct? (if I'm wrong then is there any way to reduce app size?)
Delete build folder.
Delete Pod folder from IOS Directory
.gradle folder from android Directory
& if you have release & build folder in Android then delete it
Run Command: Fluter Clean
Now Folder will be 1MB to 10MB, depending on assets folder size.
To start with i would suggest git versioning with an online (public or private) repository as a good way to back up your code. To answer your Question, There's absolutely no problem with leaving out the build folder, Actually almost by default git will ignore the build folder. Note that every time you compile the app, that build folder is refreshed, actually its always good to start by cleaning it
In IntelliJ idea base ides (like Android Studio), you can get a lightweight .zip backup from your code.
Just follow this path in the top menu:
File> Export> Project to Zip File

I have some errors in flutter installation

I need some help in solving this problem in flutter installation
i Installed flutter put when running flutter doctor show an error
./flutter/bin/flutter: line 46: /c/src/flutter/flutter/bin/cache/dart-sdk/bin/pub: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (8 tries left)
Go inside flutter SDK
you have to delete the cache folder inside bin and it will help you.
Thanks!
I dont know whether u downloaded git or not, cloned it or not
so I recommend u to follow step by step as directed on this site-
https://flutter.dev/docs/get-started/install/windows
and the question u asked can be solved if u copy the location of flutter.bin which is located in flutter directory after cloning git, and set path of that particular files in environment variables.
you can find environment variables on right clicking on this pc icon >properties>advanced system setting>environment variables>click on path if dont have create a new path,if having select it >edit >and paste location there.
run flutter doctor.
that's it.
in my case, when I cancel the flutter upgrade in the middle of using an Android Studio then the flutter becomes unreadable again, then when I when the flutter in the terminal will be like this:
... flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
then the solution is quite easy.
go to where the directory folder is / flutter / bin / cache /
Delete the dart-sdk folder
rename the dart-sdk.old folder to dart-sdk only
finished, your flutter is working again.