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

21

28

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

Weywadt answered 10/2, 2021 at 11:48 Comment(3)
Did you find any solution for this issue, I also get the same issue :-(Radiotelephony
@PulsaraSandeepa checkout my answer. I Just found a solution to this issue.Mosstrooper
see https://mcmap.net/q/503926/-flutter-build-error-process-39-command-39-e-flutter-apps-flutter-bin-flutter-bat-39-39-finished-with-non-zero-exit-value-1Declarer
Z
20

The solution that worked for me was:

  1. Delete pubspec.lock file
  2. Do flutter pub get
  3. Run the project

And it worked.

Zionism answered 20/9, 2021 at 16:2 Comment(0)
S
9

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
Spooner answered 8/5, 2021 at 22:26 Comment(0)
M
3

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.

Mosstrooper answered 31/3, 2021 at 13:28 Comment(0)
A
2

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

Appose answered 14/2, 2021 at 7:56 Comment(1)
You have to set the targetSdkVersion to 30 because the Play Store won't allow you to upload any appbundle targeted with the version 29.Fetishism
S
2
Slowmoving answered 28/4, 2021 at 7:54 Comment(1)
@TonnyBaw this may or may not work for everyone as in the github also it worked for few people. So, maybe you can try something else mentioned above by other users.Slowmoving
P
2

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

Pied answered 10/6, 2021 at 0:25 Comment(0)
A
2

(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
Alley answered 7/3, 2022 at 14:57 Comment(0)
A
2

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

Alchemy answered 3/9, 2022 at 11:37 Comment(0)
N
1

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

N answered 9/2, 2022 at 0:7 Comment(0)
D
1

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

Dusty answered 11/3, 2022 at 1:40 Comment(0)
V
1

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

Violaviolable answered 14/3, 2022 at 10:38 Comment(0)
M
1

After I upgraded to Android Sdk 31, this happened to me. What solved was the answer suggested by @Elias Fazel above but before doing that, I first needed to edit my gradle.properties file. I 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, and then it worked.

android:exported=true
Meister answered 15/4, 2022 at 16:4 Comment(0)
S
1

I have wrestled with this thing for some time. The issue is most likely due to a Gradle update. You need to update Gradle on your Flutter project as well.

You might also need to update you Target, Compile Version SDK and Kotlin version just to rule that out.

  1. Go to android/app/build.gradle and update the Gradle classPath as below

classpath 'com.android.tools.build:gradle:7.1.2'

  1. Go to android/app/gradle-wrapper.properties

distributionUrl=https://services.gradle.org/distributions/gradle-7.4-all.zip

Once done, run flutter.

Battle won, but the war with Gradle continues, until next time.

Surf answered 20/11, 2023 at 10:22 Comment(0)
P
0

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.

Procopius answered 10/2, 2021 at 11:48 Comment(0)
A
0

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.

Anaerobic answered 16/5, 2021 at 9:17 Comment(0)
D
0

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.

Dibranchiate answered 1/9, 2021 at 12:26 Comment(0)
L
0

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 .

Luxuriate answered 13/5, 2022 at 19:46 Comment(0)
S
0

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.

Slumberous answered 6/7, 2022 at 14:55 Comment(0)
A
0

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

Askari answered 26/8, 2022 at 12:57 Comment(0)
N
0

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

and problem solved.

Notify answered 21/9, 2022 at 11:46 Comment(0)
T
0

I got this error while generating apk. First I run flutter clean and Flutter pub get then flutter build apk worked for me.

Terrorstricken answered 24/4 at 7:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.