Solutions to Flutter error: Gradle task assembleDebug failed with exit code 1
1 min readNov 26, 2019
For creating an apk for Android in Flutter this issue sometimes happens. I had the luck of facing this issue as well. Here are the few ways it can be solved:
- Due to androidX
If you followed recommended route from here:
https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
Try this:
Check with steps in “not recommended” way in above tutorial if every listed files is same as in your project, especially :
- in
root/android/gradle/wrapper/gradle-wrapper.properties
setdistributionUrl=https\://services.gradle.org/distributions/gradle-7.10.0-all.zip
- in
root/android/build.gradle
, setdependencies { classpath 'com.android.tools.build:gradle:4.3.1' }
- check if in
root/android/app/build.gradle
SDK version is set to minimum 30 for:compileSdkVersion 30
andtargetSdkVersion 30
If you still get error then here is what helped me:
- delete .gradle and .m2 folders from
$HOME
directory, as well with in app folders:root/android/.gradle
androot/build
flutter doctor
flutter clean
flutter packages pub cache clean
- if you changed (as me) app icon then run:
flutter packages pub run flutter_launcher_icons:main
it will render icons for app - without it print same error with gradle.. - Invalidate caches in Android Studio
"File" > "Invalidate Caches / Restart..."
Mac + Android Studio, in my case relatively special, following NOT work:
- try
flutter doctor -v
but all environment is OK - set
android.useAndroidX
andandroid.enableJetifier
totrue
- change android device: real phone xiaomi9 / emulator Nexus 5/ emulator Pixel 2
flutter clean
- change
minSdkVersion
from16
to21
- delete some (suspicious) dart code
and finally INDEED work by:
- reboot my Mac