参考:
Android studio 全局搜索 ArtifactRepositoryContainer
即可查看依赖的maven仓库详细地址:
String DEFAULT_MAVEN_CENTRAL_REPO_NAME = "MavenRepo";
String DEFAULT_MAVEN_LOCAL_REPO_NAME = "MavenLocal";
String MAVEN_CENTRAL_URL = "https://repo.maven.apache.org/maven2/";
String GOOGLE_URL = "https://dl.google.com/dl/android/maven2/";
打开Android studio 的 setting 找到如下位置,测试Google
仓库地址的网络是否正常访问:
这里不可访问,提示如下:
我们可以换成阿里云仓库即可。
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven{ url 'https://maven.aliyun.com/repository/google'}
maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'}
maven{ url 'https://maven.aliyun.com/repository/public'}
maven{ url 'https://maven.aliyun.com/repository/jcenter'}
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven{ url 'https://maven.aliyun.com/repository/google'}
maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'}
maven{ url 'https://maven.aliyun.com/repository/public'}
maven{ url 'https://maven.aliyun.com/repository/jcenter'}
google()
mavenCentral()
// jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Unexpected tokens (use ‘;’ to separate expressions on the same line)
//Unexpected tokens (use ';' to separate expressions on the same line)
//android studio-2024.1.1版本 新写法
maven{ url=uri("https://maven.aliyun.com/repository/google")}
maven{ url=uri("https://maven.aliyun.com/repository/gradle-plugin")}
maven{ url=uri("https://maven.aliyun.com/repository/public")}
maven{ url=uri("https://maven.aliyun.com/repository/jcenter")}
阿里云maven仓库
仓库名称 | 阿里云仓库地址 | 阿里云仓库地址(老版) | 源地址 |
---|---|---|---|
central | https://maven.aliyun.com/repository/central | https://maven.aliyun.com/nexus/content/repositories/central | https://repo1.maven.org/maven2/ |
jcenter | https://maven.aliyun.com/repository/jcenter | https://maven.aliyun.com/nexus/content/repositories/jcenter | http://jcenter.bintray.com/ |
public | https://maven.aliyun.com/repository/public | https://maven.aliyun.com/nexus/content/groups/public | central仓和jcenter仓的聚合仓 |
https://maven.aliyun.com/repository/google | https://maven.aliyun.com/nexus/content/repositories/google | https://maven.google.com/ | |
gradle-plugin | https://maven.aliyun.com/repository/gradle-plugin | https://maven.aliyun.com/nexus/content/repositories/gradle-plugin | https://plugins.gradle.org/m2/ |
spring | https://maven.aliyun.com/repository/spring | https://maven.aliyun.com/nexus/content/repositories/spring | http://repo.spring.io/libs-milestone/ |
spring-plugin | https://maven.aliyun.com/repository/spring-plugin | https://maven.aliyun.com/nexus/content/repositories/spring-plugin | http://repo.spring.io/plugins-release/ |
grails-core | https://maven.aliyun.com/repository/grails-core | https://maven.aliyun.com/nexus/content/repositories/grails-core | https://repo.grails.org/grails/core |
apache snapshots | https://maven.aliyun.com/repository/apache-snapshots | https://maven.aliyun.com/nexus/content/repositories/apache-snapshots | https://repository.apache.org/snapshots/ |
gradle 配置指南
在 build.gradle 文件中加入以下代码:
allprojects {
repositories {
maven {
url 'https://maven.aliyun.com/repository/public/'
}
mavenLocal()
mavenCentral()
}
}
如果想使用其它代理仓,以使用spring仓为例,代码如下:
allProjects {
repositories {
maven {
url 'https://maven.aliyun.com/repository/public/'
}
maven {
url 'https://maven.aliyun.com/repository/spring/'
}
mavenLocal()
mavenCentral()
}
}
加入你要引用的文件信息:
dependencies {
compile '[GROUP_ID]:[ARTIFACT_ID]:[VERSION]'
}
执行命令:
gradle dependencies 或 ./gradlew dependencies 安装依赖