Flutter
25-08-2021
How to solve “Could not resolve all artifacts for configuration 'classpath'.” while building your flutter project
Quick way to solve flutter runtime error

Sometimes when you try to run to flutter project for the first time you can come across this kind of error bellow:

Launching lib/main.dart on INE LX2 in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* Where:
Build file '/home/etienne-bobo/AndroidStudioProjects/demo/android/app/build.gradle' line: 26

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not resolve all artifacts for configuration 'classpath'.
   > Could not find com.android.tools.build:gradle:4.1.0.
     Searched in the following locations:
       - https://jcenter.bintray.com/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         unspecified:unspecified:unspecified

* 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 6s
Exception: Gradle task assembleDebug failed with exit code 1


To solve this problem just open your flutter.gradle file (you will find it in flutter/packages/flutter_tools/gradle/flutter.gradle) and change

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
    }
}

to

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
    }
}

then save your file

Hope it helps you 😌😌