工程中根路径下的build.gradle文件
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
allprojects {
repositories {
jcenter()
}
}
内容主要包含了两个方面:一个是声明仓库的源,这里可以看到是指明的jcenter(), 之前版本则是mavenCentral(), jcenter可以理解成是一个新的中央远程仓库,兼容maven中心仓库,而且性能更优。另一个是声明了android gradle plugin的版本
某个Mode中的build.gradle文件
apply plugin: 'com.android.application' //表示是一个应用程序的模块,可独立运行
//apply plugin: 'com.android.library' //表示是一个依赖库,不能独立运行
android {
compileSdkVersion 25 //指定项目的编译版本
buildToolsVersion "25.0.1"//指定项目构建工具的版本
defaultConfig {
applicationId "com.sugar.myapplication" //指定包名
minSdkVersion 14//指定最低的兼容的Android系统版本
targetSdkVersion 25//指定你的目标版本,表示你在该Android系统版本已经做过充分的测试
versionCode 1 //版本号
versionName "1.0" //版本名称
}
buildTypes { //指定生成安装文件的配置,常有两个子包:release,debug,注:直接运行的都是debug安装文件
debug{
buildConfigField("String", "releaseTime", "\""+new Date().format("yyyyMMddHHmm")+"\"")
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
release { //用于指定生成正式版安装文件的配置
minifyEnabled false //指定是否对代码进行混淆,true表示混淆
//指定混淆时使用的规则文件,proguard-android.txt指所有项目通用的混淆规则,proguard-rules.pro当前项目特有的混淆规则
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies { //指定当前项目的所有依赖关系:本地依赖、库依赖、远程依赖
compile fileTree(dir: 'libs', include: ['*.jar'])//本地依赖
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:25.0.1'//远程依赖,com.android.support是域名部分,appcompat-v7是组名称,25.0.1是版本号
compile project(':hello')//库依赖
testCompile 'junit:junit:4.12' //声明测试用列库
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
}
引入依赖库
// Android support
compile "com.android.support:appcompat-v7:25.3.0"
compile "com.android.support:cardview-v7:25.3.0"
compile "com.android.support:design:25.3.0"
compile "com.android.support:recyclerview-v7:25.3.0"
// Retrofit
compile "com.squareup.retrofit2:retrofit:2.2.0"
compile "com.squareup.retrofit2:converter-gson:2.2.0"
compile "com.squareup.retrofit2:adapter-rxjava2:2.2.0"
compile "com.squareup.okhttp3:logging-interceptor:3.4.1"
compile "com.squareup.okhttp3:okhttp:3.4.1"
// RxJava
compile "io.reactivex.rxjava2:rxjava:2.0.1"
compile "io.reactivex.rxjava2:rxandroid:2.0.1"
compile "com.jakewharton.rxbinding2:rxbinding:2.0.0"
// Glide
compile "com.github.bumptech.glide:glide:3.6.1"
compile "com.github.bumptech.glide:okhttp-integration:1.3.1"
compile "jp.wasabeef:glide-transformations:2.0.1"
//Butterknife
compile "com.jakewharton:butterknife:8.8.1"
//fragmentation
compile "me.yokeyword:fragmentation:1.1.6"
//Logger
compile "com.orhanobut:logger:1.15"
//circle imageview
compile "de.hdodenhof:circleimageview:2.1.0"
//BaseRecyclerViewAdapterHelper
compile "com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.22"
//SwitchButton
compile "com.kyleduo.switchbutton:library:1.4.6"
//PhotoView
compile "com.bm.photoview:library:1.4.1"
compile "com.cocosw:bottomsheet:1.3.0@aar"
//permissions
compile "com.tbruyelle.rxpermissions2:rxpermissions:0.9.4@aar"
//Bugly
compile 'com.tencent.bugly:crashreport:latest.release'