Flutter failed to compile apk: Finished with error: Gradle task assembleDebug failed with exit code 1 Flutter failed to compile apk: Finished with error: Gradle task assembleDebug failed with exit code 1 flutter flutter

Flutter failed to compile apk: Finished with error: Gradle task assembleDebug failed with exit code 1


try follow steps:
1. in gradle-wrapper.properties, downgrade from 5.1.1 to 4.10.2.
2. int root/build.gradle, change android gradle version into 'com.android.tools.build:gradle:3.3.2'Hope it is useful


It is common after migration 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-4.10.2-all.zip (probably you have version 5.1.1 )
  • in root/android/build.gradle, set dependencies { classpath 'com.android.tools.build:gradle:3.3.2'}

  • check if in root/android/app/build.gradle SDK version is set to minimum 28 for: compileSdkVersion 28 and targetSdkVersion 28

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:mainit will render icons for app - without it print same error with gradle..

  • Invalidate caches in Android Studio "File" > "Invalidate Caches / Restart..."

If nothing from above works open android project as module

(you can do it by opening any file inside android folder for example manifest, then bar above code will shows with link to "Open for Editing in Android Studio", more here https://flutter.dev/docs/development/tools/android-studio )

Then click on gradle tab on the left and compile app - should show now more detailed error message.


Ok so here is your fix, open android sdk settings and uncheck Hide Obsolete Packages and in sdk tools, Check Android SDK Tools (Obsolete) than click ok/apply. It will download old SDK. Than Restart the IDE, Run default flutter program on emulator. This error occurs because flutter isn't compatible with latest Android SDK so you have yo manually install old SDK in Android studio.