The difference between repositories in different locations of Android Studio

The Baidu literal translation of repositories is "warehouse". As the name implies, some open source third-party libraries are imported here.

Under normal circumstances, we will add relevant configuration content in the buildscript and allproject at the same time when adding

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

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

The repositories in the buildscript indicate that only the gradle compilation tool will use this repository.
like inside buildscriptinsidedependencies classpath "com.android.tools.build:gradle:4.0.0"

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

The repositories in allprojects indicate that the libraries in each gradle in the project will depend on these repositories.

For example, dependenciesthe dependent library in will be found in allprojectstherepositories

dependencies {
    
    
	implementation platform('com.google.firebase:firebase-bom:xx.x.x')
    implementation 'com.google.firebase:firebase-analytics'
}

Finally, if we are not sure whether the imported third-party library is a dependency required by the project or a dependency required by the gradle script execution, the simplest and rude way is to add both in buildscriptandallproject

Reference link:
1. Repositories and allprojects configuration of Android Studio Gradle
2. The difference between repositories in Android stdio build.gradle buildscript and repositories in allprojects

Guess you like

Origin blog.csdn.net/EverNess010/article/details/126041743