dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile project(':hello')
}
Android Studiod中的依赖方式:1.本地依赖 2.库依赖 3.远程依赖
1.本地依赖:对本地包的jar包或者目录添加依赖关系
例如:compile fileTree(include:['*.jar'], dir:'libs') 是将libs目录下的所有.jar后缀添加懂啊项目的构建路径下。
2.库依赖:对项目中的库模块添加依赖,它的基本洗发都是compile project加需要依赖的库名称
例如:compile project(':hello')
3. 远程依赖:是对jcenter库上的开源项目添加依赖声明
例如:compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
这是一个远程依赖,其中com.android.support是域名部分,用于和其他公司的库进行区分;appcompat-v7是组名称,用于同一个公司的不同库进行区分,最后的26.0.0-alpha1是版本号,用于同一个库的不同版本区分。
对于远程库,Gradle在构建项目时会首先检查本地是否已经有该库的缓存,如果没有则自动联网下载,在添加到构建路径中。