Kotlin and Android Development featuring Jetpack: allprojects should be moved to settings.gradle (page 245)

The allprojects block listed on page 245 produces the following error when syncing gradle:

“org.gradle.api.GradleScriptException: A problem occurred evaluating root project ‘Android Baseball League
Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository ‘Google’ was added by build file ‘build.gradle’’”

A search online lead me to this post which mentioned a working fix:

Using the suggestion from stack overflow, the fix is:

Remove the code segment:

allprojects { 
   repositories { 
      google()
      jcenter()
      maven{ url 'https://jitpack.io' } 
   }
}

Then modify the “settings.gradle” file to include “maven { url ‘https://jitpack.io’ }”. The file should look something like this when complete:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
        jcenter() // Warning: this repository is going to shut down soon
    }
}

Just wanted to give a heads up to anyone else working through this fantastic book.

1 Like