I’m trying to run the application in the android emulator but this error keeps popping.
FAILURE: Build failed with an exception.
* Where:
Script 'C:flutterpackagesflutter_toolsgradleflutter.gradle' line: 1005
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:flutterbinflutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3m 33s
Exception: Gradle task assembleDebug failed with exit code 1
I have tried the following with no help.
flutter channel stable
flutter upgrade --force
flutter pub cache repair
flutter clean
in case anyone can help.
10
Answers
Try this:
Nothing should changed in your git changes due to .gitignore file
Open Android Studio again
Go to File->Invalidate Caches/Restart, then invalidate caches and restart
if your project structure is corrupted go to: File -> Close Project, close project and reopen it, it should be back to normal.
Run all the necessary scripts starting with:
flutter pub get
dart pub get
For me the thing was to delete
android/app/build
folder and runflutter clean
.Working solution:
Just uninstall/remove the entire
flutter
SDK folder and reinstall the same version of a flutter you have currently from the below link.Flutter SDK as per version: https://flutter.dev/docs/development/tools/sdk/releases?tab=macos
After the new
flutter
is installed. Just doflutter clean
and run the app.For my case, I found my code incompatible with my flutter version as I used flutter upgrade once. So I had to downgrade (delete the flutter folder manually in your src folder and extract the version that supports my code) my flutter sdk in C:srcflutter to the version that my app supports. After running
flutter clean
(which just deletes the files that flashrow has mentioned) it got solved for me.2022 Working Solution
I got the same error after running my app on a physical device. This may happen if the compile SDK version is lower than that of the physical device. This error message is not limited just to running on physical devices however, here is the solution.
Go to
android/app/build.grade
Find
The change the compileSdkVersion to 31
In the future, the maximum compileSdkVersion might increase, so try 32, or 33 if it doesn’t work
Try to run with the
-v
parameter to see a better logging console. In my case, some plugins are generating the following error:When I saw it, I run with the option
--no-sound-null-safety
and I could start my app in the emulator.Apperently this seems like a null safety related issue.
lowering down the Dart sdk’s version from pubspec.yaml could solve this issue.
upgrade your dependencies in your pubspec.yaml
I had this problem in (line 1156) when I wanted to build an APK file, after almost executing solutions to solve it, finally found this command
build release apk:
build apk with the lowest size:
I could build my APK very well
I have updated version of gradle to latest.
Path : android/build.gradle(project level gradle file)