Flutter: Execution failed for task ':app:compileDebugKotlin'

58,953

Solution 1

I solved it. It was because of my network blocked non secured http download request. I changed my network and the gradle build completed itself.

Solution 2

Go to your build.gradle file in the root of your Android directory and upgrade your Kotlin_version to the latest. As of the time of typing this, the latest is 1.5.10, so it should look like this:

ext.kotlin_version = '1.5.10'

Solution 3

Solved the problem by deleting android/.gradle then ran the app in debug

Solution 4

A possible fix can be upgrading the project/android/build.gradle Steps to fix,

  1. flutter clean
  2. Delete android/.gradle
  3. Go to android/build.gradle, upgrade ext.kotlin_version to latest. In my case(1.3.0 -> 1.5.10), ext.kotlin_version = '1.5.10'

After doing this as well, I was getting `A problem occurred evaluating project ':app'.

Failed to apply plugin [id 'kotlin-android'] The current Gradle version 5.6.2 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.1 or newer, or the previous version of the Kotlin plugin.`

To fix this,

  1. Go to android/gradle/wrapper/gradle-wrapper.properties
  2. Update the distributionUrl to the latest version.In my case((5.6.2 -> 6.1.1) it is, distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

Solution 5

For me, I found that when building that 2 different MainActivity.kt files were in andriod/app/src/main/kotlin. One had a default MainActivity.kt file with the package name that was originally generated for my project. Something like 'example.project_name' . The other one had what I changed my project name into. I went ahead and deleted the folder with the MainActivity.kt containing the import starting with 'example.project_name' and that resolved the issue for me.

Share:
58,953
Serpentarius
Author by

Serpentarius

Updated on May 13, 2022

Comments

  • Serpentarius
    Serpentarius almost 2 years

    I tried running the default flutter app from flutter create on my android device but it throws me an error. Can someone help?

    Launching lib\main.dart on SM G610F in debug mode... Running Gradle task 'assembleDebug'...

    FAILURE: Build failed with an exception.

    • What went wrong: Execution failed for task ':app:compileDebugKotlin'.

      Could not resolve all artifacts for configuration ':app:debugCompileClasspath'. . . .

    • 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 14s Finished with error: Gradle task assembleDebug failed with exit code 1

    This is my flutter doctor:

    [√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.10586], locale en-US) • Flutter version 1.12.13+hotfix.5 at E:\flutter\flutter • Framework revision 27321ebbad (6 weeks ago), 2019-12-10 18:15:01 -0800 • Engine revision 2994f7e1e6 • Dart version 2.7.0

    [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at C:\Users\208046\AppData\Local\Android\sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-29, build-tools 29.0.2 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03) • All Android licenses accepted.

    [√] Android Studio (version 3.5) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin version 42.1.1 • Dart plugin version 191.8593 • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

    [√] VS Code, 64-bit edition (version 1.41.1) • VS Code at C:\Program Files\Microsoft VS Code • Flutter extension version 3.7.1

    [√] Connected device (1 available) • SM G610F • 33005566b2b5c3df • android-arm • Android 8.1.0 (API 27)

    • No issues found!

    edit: for my complete logs you can see here:

    Flutter github issues

    • Abhilash Chandran
      Abhilash Chandran over 4 years
      As suggested here, this could be an issue with the android/kotlin build. I assume you successfully created a flutter project. In that case did you try to do a flutter clean. Also please mention the steps you already followed, that could help.
    • Serpentarius
      Serpentarius over 4 years
      All I did was create a new flutter project from VS Code and run on my device. That's it. This is very frustrating because I created a web flutter project and I can run it just fine.
    • Abhilash Chandran
      Abhilash Chandran over 4 years
      Please don't be frustrated. :-) Based on the logs in your github post it looks like the build process is trying to download some jar files which are not available in server. Good that you posted the same in Github. Just a hunch, could you try to run on a simulator instead of a device.
    • Serpentarius
      Serpentarius over 4 years
      I just recreated the project on my coworker pc and it ran fine on android device
    • Karolina Hagegård
      Karolina Hagegård almost 3 years
      I had the same problem but for release: Execution failed for task ':fluttertoast:compileReleaseKotlin'. And flutter clean took care of it! 😆 (When will I learn to just try that for all problems?! 🤦🏻‍♀️)
  • Zionnite
    Zionnite almost 3 years
    where can i find in Mac?
  • theeomm
    theeomm almost 3 years
    @Zionnite does not matter which OS you are using. flutter_project_root/android/.gradle
  • theSpuka
    theSpuka almost 3 years
    Why is this not the accepted answer? Someone deserves the credit!
  • Pro Co
    Pro Co almost 3 years
    Showing gradew is not recognizable? why?
  • Tushar Gautam
    Tushar Gautam almost 3 years
    @ProCo which OS are you using? if it is linux, cd into your project's android/ and then try doing ./gradlew clean
  • user872985
    user872985 almost 3 years
    Thank you! It fixed my problem when adding the package audioplayers: ^0.19.0 I started on the flutter code using 'Flutter create' 2 days ago and this created a build.gradle file with 'ext.kotlin_version = '1.3.50'
  • Johanna
    Johanna over 2 years
    thanks for the detailed solution. it worked for me.
  • harlekintiger
    harlekintiger over 2 years
    Is there a place explaning the update process of such things? For example my dependencies classpath is also requesting some sort of update
  • Ilo Calistus
    Ilo Calistus over 2 years
    Which exact dependencies is requesting an update?
  • Abdallah El-Rashedy
    Abdallah El-Rashedy over 2 years
    It's works with me, thanks
  • Wimukthi Rajapaksha
    Wimukthi Rajapaksha over 2 years
    sometimes you may get ':app:mergeDexDebug' error after this fix. Refer stackoverflow.com/a/60311131/10505343 after that
  • Mohamed Raza
    Mohamed Raza over 2 years
    this works perfectly thank you. I found the build.gradle under the project->android->build.gradle
  • Tanvir Ahmed
    Tanvir Ahmed over 2 years
    ah man thanks it works!
  • Eray Hamurlu
    Eray Hamurlu over 2 years
    thanks worked for me. By the way don't forget after upgrade kotlin version.
  • Ced
    Ced about 2 years
    what is inside that folder ?
  • Hardik
    Hardik almost 2 years
    Solved by "flutter clean" then "flutter pub get"