91

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

5
  • 2
    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. Commented Jan 24, 2020 at 9:05
  • 1
    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. Commented Jan 24, 2020 at 9:10
  • 1
    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. Commented Jan 24, 2020 at 9:21
  • I just recreated the project on my coworker pc and it ran fine on android device Commented Jan 24, 2020 at 9:23
  • 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?! 🤦🏻‍♀️) Commented May 1, 2021 at 14:30

30 Answers 30

118

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'

You can find the latest Kotlin version here.

Sign up to request clarification or add additional context in comments.

7 Comments

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'
Is there a place explaning the update process of such things? For example my dependencies classpath is also requesting some sort of update
Which exact dependencies is requesting an update?
this works perfectly thank you. I found the build.gradle under the project->android->build.gradle
FYI, to find the latest Kotiln's version, you can get i from here
|
68

Solved the problem by deleting android/.gradle and then run the app in debug mode

5 Comments

where can i find in Mac?
@Zionnite does not matter which OS you are using. flutter_project_root/android/.gradle
Why is this not the accepted answer? Someone deserves the credit!
what is inside that folder ?
Solved by "flutter clean" then "flutter pub get"
34

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

Comments

12

It was fixed after I upgraded my build.gradle file ext.kotlin_version = '1.5.10'

First of all run

flutter clean
flutter pub get

Go to andriod/build.gradle then upgrade ext.kotlin_version

buildscript {
    ext.kotlin_version = '1.5.10'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
} 

Comments

8

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.

Comments

8

in android folder of your project run in terminal

gradlew clean

Then build. This worked for me.

2 Comments

Showing gradew is not recognizable? why?
@ProCo which OS are you using? if it is linux, cd into your project's android/ and then try doing ./gradlew clean
5

I Update Flutter from 2.10.4 to Flutter 3.0.0 and I found All My Project Has Same Error

ensure that your ext.kotlin_version is '1.6.10'

ext.kotlin_version = '1.6.10'

and run in terminal

flutter pub cache repair

and show that your libraries in pubspec.yamel take last version and run in terminal

1 - flutter clean

2 - flutter pub get

in android studio open File --> invalidate cashes..

this worked for me !!

if this not work for you you may be need to

Delete android/.gradle

thank you .

1 Comment

flutter pub cache repair | Saved my day
5

I fix my issue here changing the file android/settings.gradle

FROM THIS

.
.
.
plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}
.
.
.

TO THIS

.
.
.
plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}
.
.
.

Comments

4

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.

1 Comment

That's great, but can you explain how you found this?
4

It was fixed after I upgraded my Flutter by running flutter upgrade

Comments

4

I Solved it by upgrading kotlin version in root build.gradle file:

ext.kotlin_version = '1.5.10'

Comments

4

First of make sure that you have latest version of flutter. For confirmation, please run flutter upgrade in command prompt / terminal:

flutter upgrade

Then visit the site Click Here and copy the new latest version of kotlin. For now: in March 02, 2022 current kotlin version is 1.6.10

Then after it:

-> Go to android/build.gradle
-> change to ext.kotlin_version = '1.6.10'

Click here to view Screenshot example

1 Comment

its not always the case to upgrade the flutter. in case of the old projects upgrading versions without knowing the issue can make so much problem
3

I got the problem after migrating to null-safety. I fixed it by updating the kotlin version in the file android\build.gradle

ext.kotlin_version = '1.3.50'

Then run 'flutter clean' and the app worked fine.

Comments

2

I have been facing this issue for couple of hours. At the end right now my issue solved by executing following steps -

- change Settings -> Build, Execution, Development -> Compiler -> Kotlin Compiler -> Kotlin to JVM -> check Enable incremental comilation -> Target JVM version 1.6 to 1.8

- add to build.gradle under repositories in both buildscript and allprojects section

maven {
        url 'http://download.flutter.io'
    }

-and lastly run on command line 'flutter pub cache repair'

enter image description here

Comments

2

I encountred the same problem and tried all the solutions proposed here in this post ... and still not working.

but only after upgrading the packages in pubspec.yaml with:

flutter pub upgrade

it worked !!

Comments

2

Just increase the ext.kotlin.version from whatever version you have, to '1.4.32' or whatever the latest version is available kotline version

Comments

2

Update to the latest version in my case it is 1.6.10 or create dummy project and check android/build.gradle and update.

ext.kotlin_version = '1.6.10'

Comments

2

For me, upgrade to Flutter 3.7.6 solved my problem, just run on your terminal

flutter upgrade

Comments

1

In our case, the package flutter_appcenter_bundle caused this issue.

To fix it, you need to run flutter precache.

This needs to be done only once and it will be effective as long as the Flutter version remains unchanged and the precached artifacts are not deleted (e.g. by deleting the Flutter root folder).

Also, the environment variable FLUTTER_ROOT needs to be set to the Flutter root folder. On Windows it's usually C:\src\flutter.

If you use AndroidStudio, you can do that in Settings > Languages & Frameworks > Flutter.

If you don't use AndroidStudio, you need to set FLUTTER_ROOT manually.

1 Comment

This solved my problem (been hunting for the solution for multiple days now). Thank you.
1

If you are sure it's not an issue with kotlin version or you need a newer version of the Android gradle plugin, then try the following

1.Delete android/.gradle

for macOS users:

sudo rm -r $HOME/.gradle

2- Delete flutter pub-cache

rm -r $HOME/.pub-cache  

3- Repair the flutter cache:

flutter pub cache repair

4- get the dependencies and build your flutter app

flutter build apk

Alternatively, delete the dependency that the build is complaining about Then!

1.Get the dependencies without the pub that is causing problems

flutter pub get

2.Fix the cache

flutter pub cache repair

3.Build the app (for android per ex)

 flutter build apk

4.Add again the dependency that was causing problems 5.Get the dependencies

flutter pub get

You are all set!

Comments

0

when I ran flutter upgrade in the command line prompt it was fixed and ran my app .. try it

Comments

0

Faced the same issue: Execution failed for task ':app:compileDebugKotlin'. Execution failed for task ':app:compileDebugKotlin'.

solution: Changed the company domain with only one dot. solution

Comments

0

I was using JRE for Java. I just install the AdoptOpenJDK 11 and it works

Comments

0

In my case, I had to set the JavaVersion according to the Kotlin version.

So to fix this error:

'compileDebugJavaWithJavac' task (current target is 1.7) and 'compileDebugKotlin' task (current target is 17)

I had to set this values in the file build.gradle:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}

Comments

0

In Flutter 3.27.1 I got the same error while integrating shared_preferences into my project, and the reason is the version of

com.android.application

in android/settings.gradle file

changing from:

id "com.android.application" version "8.1.0" apply false

to

id "com.android.application" version "8.2.1" apply false

Comments

0

I solved this issue on Windows by running the following commands in the terminal from my project's root directory. This process cleans the Gradle build cache, resolving the error.

  1. First, navigate into the android folder:

    cd android
    
  2. Then, run the clean command:

    gradlew.bat clean
    

After these two steps, the build worked successfully.

Comments

0

Comment out the code in android/app/src/main/kotlin/<app bundle name>/MainActivity.kt.

Comments

-1

For me, my package name imported twice automatically in MainActivity file under app>main>kotlin directory. I just delete duplicates and it works fine now!

Comments

-1

Please verify your existing Kotlin version. If you're working with Android Studio, you can do this by navigating to Tools -> Kotlin -> Configure Kotlin Plugin Updates. Once you've identified the current version, proceed to the android/build.gradle file and update the ext.kotlin_version to match that version.

Comments

-3

Run "flutter clean" and get dependencies again

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.