'Problem with adding repositories in build.gradle(project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        maven { url "https://jitpack.io" }
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

This is the error i am getting

A problem occurred evaluating root project 'LuckyMuch'.

Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'

  • Try: Run with --info or --debug option to get more log output. Run with --scan to get full insights.


Solution 1:[1]

Even I faced this issue, I have updated settings.gradle file with below code it worked for me

dependencyResolutionManagement {
     repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
     repositories {
         google()
         mavenCentral()
     }
}
rootProject.name = "Chat App"
include ':app'

Solution 2:[2]

I have the same problem and solved it. Go to settings.gradle file -> change below code: From this:

repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

to this:

repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

and add this line in the repository block: maven { url 'https://jitpack.io' }

Solution 3:[3]

dependencyResolutionManagement {
  repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
 repositories {
     google()
     mavenCentral()
 }

} rootProject.name = "Chat App"

include ':app'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Muralikrishna G S
Solution 2
Solution 3 Depezo