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 { 
      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 {
    repositories {
        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

@jonmac is correct with this change! If you create a project with newer Android Studio versions, it sets up a centralized repository declaration (which is the last code block in the post above) rather than requiring you to declare your repositories in each submodule.

While we don’t need it in this particular app, in real apps there’s a great chance you’ll want multiple modules meaning this helps a bunch.

If you want more info, check out this link: Declaring repositories