How to solve flutter.gradle and flutter.bat error?Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' && flutter.bat error - flutter

FAILURE: Build failed with an exception.
Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991
What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

The solution that worked for me was:
Delete pubspec.lock file
Do flutter pub get
Run the project
And it worked.

I was able to get around this by running with null safety turned off. See this article for details.
dart --no-sound-null-safety run
flutter run --no-sound-null-safety

Maybe this outdated but should help someone.
Yesterday I Just restarted my pc and got this issue. I tried to search for the solution to this problem but nothing works in my case.
Solution
Just delete your flutter folder (Flutter Source) and then reinstall it. Your problem will solve.

First flutter clean then flutter run worked for me. Ref - https://github.com/flutter/flutter/issues/75139. Thanks to https://github.com/darshankawar

Definitely, the problem is from ur Gradle settings.
For me, when I got the error, the problem was from the app/build.gradle file. there, my minSdkVersion was set to 23, so I just changed it to 21 and the error was solved. I will suggest u check your targetSdkVersion is set to 29 and compileSdkVersion is 29. I hope this help you too

In my case, I moved the project folder to D:, flutter clean, pub get and it runs

(In my case this error occurred after I upgrade Android Sdk to 31)
Go to AndroidManifest.xml and Set this to all Activities with
android:exported=true

if you build apk with --obfuscate, don't forget add a dot to head of your
--split-debug-info directory.
flutter build apk --obfuscate --split-debug-info=/projectfolder/debug
to
flutter build apk --obfuscate --split-debug-info=./debug
worked for me

I tried flutter clean, reinstalling SDK. Nothing worked.
My folder name was not correct. It was mvvm,provider test I changed it to mvvm_provider_test. Then it worked.

This error happened when I added a certain plugin. It turned out that the plugin required a minSdkVersion of 18. After I changed that, I did a flutter clean and after that, flutter pub get. So from this, I believe if you just added a recent plugin before you started facing this issue you look through the documentation of that plugin for installation info.
Also, after I did the above I had to restart my pc.

In case you're using flutter in command-line, just add -v which will run any flutter command in verbose mode. This should show you the origin of an error.
Like for me I was building with --split-debug-info and the folder I chose did not exist

In my case, what worked for me was removing the pubspec.lock and then doing a flutter pub get in my vscode command console, being in my project. Then modify the android\app\build.gradle file. inside the file I had compileSdkVersion 30 and update to version 31, being as follows compileSdkVersion 31

Download new Flutter SDK and update flutter path in your project,
And try again

After i upgraded to Android Sdk 31, this came for me. What solved was the answer suggested by #Elias Fazel above but before doing that, i first needed to edit my gradle.properties file. Added the following line :-
org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
This was suggested from here : How to fix the ''module java.base does not "opens java.io" to unnamed module '' error in Android Studio?
After this, i added this line to activity tag in AndroidManifest.xml & then it worked.
android:exported=true
Hope this helps.

In my case the issue was in Git
I have shifted to another branch which was merged and that causes the issue . then
checkout from the master to main problem solved .

For me, the problem was in my pubspec.yaml file. I made some changes to it got this error commented out those changes and now it works fine.

It's related with the Gradle, this issue comes when you have multiple Gradle versions in C:\Users\userName.gradle directory, the solution I made I deleted all directory files in .gradle directory, and restarted the IDE again with default gradle version who comes when you try to create the project at the first time 👉 (gradle-7.4-all.zip) this way works for me.

did face the same issue
"flutter pub cache clean" - running this command solved my issue
hope this becomes helpful

I did not find any solution so i did window again and all required software like flutter android studio etc.
and problem solved.

Related

flutter The method 'File.create' has fewer named arguments than those of overridden method 'File.create'

When I try to run my Flutter project, I get errors like:
../../../.pub-cache/hosted/pub.dev/file-6.1.2/lib/src/interface/file.dart:15:16: Error: The method 'File.create' has fewer named arguments than those of overridden method 'File.create'. Future create({bool recursive = false});
Running flutter clean and flutter upgrade didn't help. What's wrong? How do I fix this?
I kept getting the same error, But I solved it adding by adding
file: ^6.1.4 in my dependencies
If you are having the same problem. Make sure you have the latest file dependency.
I think the problem is caused by an outdated reference to file dependency. See this issue.
For fix this, on the project or library folder run:
dart pub upgrade
This command will upgrade your dependencies and the problem will be solved without adding the reference to latest version of file dependency.
I just ran in to this issue and I was on flutter's master channel. I switched back to stable (flutter channel stable) and everything works fine.
For me the packages in my pubspec.yaml were all up to date, but the following fixed it:
Delete pubspec.lock.
Run flutter pub get again.
i solved it by adding file: ^6.1.4 to my pubspec i dont know why this is needed in dependenccies but when i added it worked
this error occured to me when i was trying to update my flutter and packages
but error thrown was of transitive dependencies i guess when u defin in dependencies it over rides the transitive one
but it worked for me
but after wards once project ran i removed the file dependencie from my punspec did a flutter clean and a pub get again and ran the project again it worked without any problem

Flutter Gradle task assembleDebug failed with exit code 1 zip END header not found

Hello I am new to Flutter I have setup flutter with android studio 4.2.1, and every thing is fine. When I try to run it; it show me following error
I see too much questions but it is not helpfull for me
flutter doctor run no issue found
Hers is doctor result
Here is my enviroment variable
can any one guide me how can I run the flutter. I am lunching it in a chrome
exception in thread "main" java.util.zip.ZipException: zip END header not found at
java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1567) at
java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1462) at
java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1469) at
java.base/java.util.zip.ZipFile$Source.(ZipFile.java:1274) at
java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1237) at
java.base/java.util.zip.ZipFile$CleanableResource.(ZipFile.java:727)
at
java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:844)
at java.base/java.util.zip.ZipFile.(ZipFile.java:247) at
java.base/java.util.zip.ZipFile.(ZipFile.java:177) at
java.base/java.util.zip.ZipFile.(ZipFile.java:191) at
org.gradle.wrapper.Install.unzip(Install.java:214) at
org.gradle.wrapper.Install.access$600(Install.java:27) at
org.gradle.wrapper.Install$1.call(Install.java:74) at
org.gradle.wrapper.Install$1.call(Install.java:48) at
org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:48) at
org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
at
org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Exception: Gradle task assembleDebug failed with exit code 1
I recently Solved this problem.
This Problem came from gradle file is corrupted in my system.
I'm using Linux so this steps almost same in windows also. This answer is for any gradle version.
Open File Manager:
enable Show hidden folder from top menu bar.
You may find this location : .gradle>wrapper>dists.
In Linux: Home > .gradle > wrapper > dists.
In Windows: C:>Users>{PC Name}>.gradle>wrapper>dists
Method 1
Go inside gradle-6.5-all > dists > 2oz4ud9k3tuxjg84bbf55q0tn. '2oz4ud9k3tuxjg84bbf55q0tn' may be different in your PC.
Delete all files in that folder and download required file manually: https://downloads.gradle-dn.com/distributions/gradle-6.5-all.zip
after download paste freshly downloaded zip file in that folder.
Run your project flutter run -v
Method 2
Try this if you have fast & stable internet connection.
Delete that gradle-6.5-all folder.
Open project in VS code or Android Studio and open terminal.
Run this command flutter run -v
Method 3
Flutter Doctor will give right result.
Open Android Studio
Create new flutter project
Click on Tools > flutter >Flutter for editing in android studio
and wait, flutter doctor takes time to identify problem.
Use this link for download gradle file.
Replace 6.5 with your gradle version.
https://downloads.gradle-dn.com/distributions/gradle-6.5-all.zip
I hope this answer helpful for you.
Please use the below command
1.Mac User :
rm -rf ~/.gradle
2.Windows User :
remove the .gradle file
.gradle file location -> C:\Users\myUser
I solve this error by updating the gradle plugin/version. I have as part of my configuration:
Windows 10
Android Studio 4.2.1
Java 11: Android Studio 4.2.1 don't have support for JDK 16, so, I installed JDK 11, and configured the AS (how to change the jdk in AS) to use this older JDK
Gradle 7.0.1
By default, when you create a new Flutter project, the IDE created it with basic standard configurations, so you have to change this configs to fit your current config. For that, you need to update the gradle config in the flutter project, as follow:
in android/gradle/build.gradle file: update the gradle plugin to 4.2.0 in the dependencies section, like this:
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
//more dependencies
}
in android/gradle/wrapper/gradle-wrapper.properties file: update the gradle version, in this case I have the 7.0.1, feel free to use another one, like this
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-all.zip
//more attributes
After you change the gradle config, run this commands in your project:
flutter clean : clean the project
flutter pub get : update your dependencies
flutter run : run the project. Now it must work, at least it work for me
I faced the same problem in VSCode when I wanted to run the Flutter app I got that error, so after lots of debugging and research, I found the solution. it's pretty easy, just follow these steps:
In windows 10:
1. Open flutter project in a Text-Editor like VSCode.
2. Open android -> gradle -> wrapper -> gradle-wrapper.properties
3. You will find "gradle-6.7.1.all.zip" inside gradle-wrapper folder
4. Go to this path: C:\Users\your-user
5. Then go to the wrapper->dists and find "gradle-6.7.1.all" folder
5. Delete this folder.
6. Then come to VSCode and open Terminal.
7. Please make sure that you have stable internet connection then type this command in terminal
8. flutter run
I hope this solution can help you!
I solve this error by deleting the .gradle folder.
This location is gradle folder
In Windows: C:> Users> {PC Name}>. Gradle
After deleting this folder, you only need to run the application again in Android Studio. At this point, Android Studio starts downloading the deleted folder automatically.
enter image description here
This error is caused by corrupted gradle files, this is either due to incomplete downloads due to network issues. To solve it easily download the gradle zipped file from https://downloads.gradle-dn.com/distributions/gradle-6.7-all.zip and paste on the .gradle directory as shown below if you are on linux
enter image description here
I try all method but it did not work for me so i decided to location the gradle-wrapper.properties in the andriod folder then i change the distribution gradle link to a more recent gradle link.
Welcome SO.
Java 16/latest version is not fully compatible with the Gradle 6 at this moment. Try to use java 11 or 8, it will resolve your issue.

Flutter - Overridden dependencies

After running "flutter pub get", I got this error:
Warning: You are using these overridden dependencies:
! path 1.6.4
That's not an issue. That happens because you (or any other transitive dependency) may be overriding some dependency that you are already using. For example, if you are using path: 0.X.X and some other dependency use dependency_overrides to make sure that is using path: 1.6.4, it will present you that message.
Overall, you shouldn't have to worry with that and sometimes it is actually required in order to some dependencies work all together.
Please give more details so that i can answer it better. Attach your pubspec.yaml.
But now i can tell you some methods which should work..
first of all see if you are using the latest version of all dependencies or not then:
try:
restarting your ide
flutter clean
if these two don't work then at last try
flutter pub cache repair
I encountered the same error after cloning a flutter repository. I initially mistook the error for being a build issue when it's just a warning that won't stop your app from running.
I solved the build issue I was having with the freshly cloned project by running this command inside the app's root directory: flutter pub run build_runner build

Task :app:compileFlutterBuildDebug FAILED (Flutter)

I have issue to run demo flutter project.
log verbose :
you can try to use command
flutter clean
and then flutter run
The error might be due to the improper installation of SDK. There are several solutions as per below:
1) Invalid Cache and restart. (the common one)
2) Reinstall flutter SDK.
3) Change the gradle version with the available version of your machine.
4) Removing "android.enableR8=true" line from the android project's gradle.properties file.

The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated

I'm running a dart only test in intellij and receiving the following error:
The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated, please run "pub get" again.
I have tried pub get a number of times. Any ideas? I'm on the dev branch of Flutter (anything using Dart 2.7 pretty much fails with the same or a similar error message).
Edit
I think that if you have a path reference dependency in the pubspec.yaml file it will fail.
Anything like the following fails with the above message if you try to run a dart test in IntelliJ.
dependencies:
test_dependency:
path: ../test_dependency
I'm not suggesting this is a fix for everyone, but it did resolve my particular situation.
Just ran into this error after upgrading flutter from 1.22.6 to 2.0.2 and trying to use build_runner: ^1.12.2 and json_serializable: ^4.1.0 to generate json serialization/deserialization classes & methods.
The problem is apparently related to the pub package when used with relative paths for packages as noted in the following github issues:
https://github.com/dart-lang/pub/issues/2806
https://github.com/dart-lang/pub/pull/2830
One of the commenters in issue 2806 mentioned running flutter create . inside the flutter project folder which rebuilds .dart_tool/package_config.json, adding any missing entries, solving the problem.
No one solved this problem so far?
I've found a staightforward solution and it works fine for me.
You need to close your IDE (VSCode in my case), make sure that is completely closed using process-monitor.
Then open a terminal window manualy in your project folder and run "flutter pub get"
After that just start your IDE normaly and ewerything will work fine.