在Android Studio Koala中,为了下载插件和依赖包更加流畅,我要增加阿里云仓库地址作为插件和依赖包下载地址,应该在哪个配置文件进行添加(修改build.gradle 还是 settings.gradle.kts),如何修改?
在Android Studio中,为了使用阿里云的仓库地址来加速插件和依赖包的下载,你需要修改项目的settings.gradle.kts
文件和各个模块的build.gradle
文件。
settings.gradle.kts
在settings.gradle.kts
文件中,添加阿里云的仓库地址到插件管理的repositories中:
pluginManagement {
repositories {
gradlePluginPortal()
maven {
url = uri("https://maven.aliyun.com/repository/gradle-plugin")
}
mavenCentral()
google()
}
}
build.gradle
在项目根目录下的build.gradle
文件中,添加阿里云的仓库地址到repositories中:
allprojects {
repositories {
google()
mavenCentral()
maven {
url "https://maven.aliyun.com/repository/public"
}
maven {
url "https://maven.aliyun.com/repository/google"
}
maven {
url "https://maven.aliyun.com/repository/jcenter"
}
}
}
build.gradle
在每个模块(如app
模块)的build.gradle
文件中,确保repositories中包含阿里云的仓库地址:
repositories {
google()
mavenCentral()
maven {
url "https://maven.aliyun.com/repository/public"
}
maven {
url "https://maven.aliyun.com/repository/google"
}
maven {
url "https://maven.aliyun.com/repository/jcenter"
}
}
settings.gradle.kts
pluginManagement {
repositories {
gradlePluginPortal()
maven {
url = uri("https://maven.aliyun.com/repository/gradle-plugin")
}
mavenCentral()
google()
}
}
build.gradle
buildscript {
repositories {
google()
mavenCentral()
maven {
url "https://maven.aliyun.com/repository/public"
}
maven {
url "https://maven.aliyun.com/repository/google"
}
maven {
url "https://maven.aliyun.com/repository/jcenter"
}
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.2"
// 其他依赖
}
}
allprojects {
repositories {
google()
mavenCentral()
maven {
url "https://maven.aliyun.com/repository/public"
}
maven {
url "https://maven.aliyun.com/repository/google"
}
maven {
url "https://maven.aliyun.com/repository/jcenter"
}
}
}
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
repositories {
google()
mavenCentral()
maven {
url "https://maven.aliyun.com/repository/public"
}
maven {
url "https://maven.aliyun.com/repository/google"
}
maven {
url "https://maven.aliyun.com/repository/jcenter"
}
}
通过以上配置,你就可以使用阿里云的仓库地址来加速插件和依赖包的下载了。