Blue Moon
Blue Moon

Reputation: 431

I received an error on the first run of flutter project! `Finished with error: Gradle task assembleDebug failed with exit code 1`

Today I started to learn flutter.

I created new flutter project from Flutter Application in android studio 3.5.3.

I created new android virtual device and then tried to run main.dart.

I remember that my project freezed during initializing gradle in the first run so I had to stop and rerun main.dart and after that it raises following error:

Launching lib\main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find sdk-common.jar (com.android.tools:sdk-common:26.5.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/sdk-common/26.5.0/sdk-common-    26.5.0.jar

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

build.gradle file contains:

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

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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and settings.gradle contains:

include ':app'

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
    pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}

plugins.each { name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    include ":$name"
    project(":$name").projectDir = pluginDirectory
}

I guess that freezing was because of poor connection at the moment of initializing and sdk-common.jar didn`t download correctly.

As I mentioned above, I'm new to flutter and I don't know how to clean build the project so I repeated step by step several times but error persists.

I have no idea about this problem. Can anyone kindly help me?

Please tell me if details are not clear enough to understand.

Upvotes: 1

Views: 2134

Answers (1)

griffins
griffins

Reputation: 8246

  • What went wrong: A problem occurred configuring root project 'android'. Could not resolve all artifacts for configuration ':classpath'. Could not find sdk-common.jar (com.android.tools:sdk-common:26.5.0).

add maven to your gradle file to solve this as follows

maven { url 'https://maven.google.com' }

although i would suggest you use API 28

I don't know how to clean build the project

run flutter clean in your project root folder

Upvotes: 1

Related Questions