(1) 项目根目录下的build.gradle里repositories
节点下添加仓库地址
AS 3.0之前:
buildscript {
repositories {
//依赖的仓库
jcenter()
}
dependencies {
//项目依赖的Gradle版本
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
allprojects {
repositories {
jcenter()
//远程仓库
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
AS 3.0之后:
buildscript {
repositories {
google()
//依赖的仓库
jcenter()
}
dependencies {
//项目依赖的Gradle版本
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
//远程仓库
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
(2) 在app下的build.gradle里dependencies
节点下添加引用
AS 3.0之前:
...
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.google.code.gson:gson:2.8' //引用第三方module库(Github上开源项目)
...
}
AS 3.0之后:
...
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:25.0.0'
implementation 'com.google.code.gson:gson:2.8' //引用第三方module库(Github上开源项目)
...
}
(3) 同步更新Gradle (Sync now)