Solutions to Flutter error: Gradle task assembleDebug failed with exit code 1

Nabil Mosharraf Hossain
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:

  1. 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 set distributionUrl=https\://services.gradle.org/distributions/gradle-7.10.0-all.zip
  • in root/android/build.gradle, set
    dependencies { 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 30and targetSdkVersion 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 and root/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 and android.enableJetifier to true
  • change android device: real phone xiaomi9 / emulator Nexus 5/ emulator Pixel 2
  • flutter clean
  • change minSdkVersion from 16 to 21
  • delete some (suspicious) dart code

and finally INDEED work by:

  • reboot my Mac

--

--