'How to solve flutter.gradle and flutter.bat error?Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' && flutter.bat error
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
Solution 1:[1]
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
Solution 2:[2]
The solution that worked for me was:
- Delete
pubspec.lockfile - Do
flutter pub get - Run the project
And it worked.
Solution 3:[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.
Solution 4:[4]
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
Solution 5:[5]
- First
flutter cleanthenflutter runworked for me. Ref - https://github.com/flutter/flutter/issues/75139. Thanks to https://github.com/darshankawar
Solution 6:[6]
In my case, I moved the project folder to D:, flutter clean, pub get and it runs
Solution 7:[7]
(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
Solution 8:[8]
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.
Solution 9:[9]
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.
Solution 10:[10]
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
Solution 11:[11]
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
Solution 12:[12]
Download new Flutter SDK and update flutter path in your project, And try again
Solution 13:[13]
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.
Solution 14:[14]
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 .
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
