Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Flutter failed to compile an apk. I am not sure if this has something to do with AndroidX or something.

Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Finished with error: Gradle task assembleDebug failed with exit code 1

I ran flutter clean. I also ran flutter run -v. This is what happened: https://1drv.ms/t/s!An3OLJ7n0CjEku1SBrSABWab901z3Q

(I have used an external file locker because the stack trace is too large for the Stack Overflow editor).

This issue is similar to https://github.com/flutter/flutter/issues/30634

like image 844
randomUser786 Avatar asked Dec 08 '22 12:12

randomUser786


2 Answers

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

like image 100
Nam Pham Avatar answered Apr 24 '23 14:04

Nam Pham


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:main it 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.

like image 36
Lukk17s Avatar answered Apr 24 '23 14:04

Lukk17s