1、android中build.gradle文件简单说明
根目录下的build.gradle:
buildscript {
repositories {
jcenter() // 代码托管仓库,声明之后,就可以使用jcenter上的开源项目。
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
//用来构建android项目而开发的。使用就需要声明com.android.tools.build:gradle,后面的为版本。
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
app目录下的build.gradle:
apply plugin: 'com.android.application'
//1、使用了一个插件
//可选:com.android.application(应用程序模块) 和 com.android.library(库模块)
android {
compileSdkVersion 25 //项目编译版本
buildToolsVersion "25.0.3" //项目构建工具的版本
defaultConfig { //项目细节配置
applicationId "com.example.david.firstandroidcode" //项目包名,可修改
minSdkVersion 23 // 最低兼容android系统版本
targetSdkVersion 25 //表示在该版本上已经做了充分的测试,这个版本以及这个版本一下的功能会自动启用。比这个版本高的功能将不会启用。
versionCode 1 //项目版本号
versionName "1.0" //项目版本名
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes { //生成安装文件的配置
release {
minifyEnabled false //是否对项目的代码进行混淆
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//定义代码混淆时的配置文件
//proguard-android.txt是在android SDK目录下,定义通用的混淆规则。
//'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.3.1' //远程依赖 域名(用于区分不同公司):组名称(用于区分不同的库):版本号(区分版本)
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7' //远程依赖
//加上远程依赖后,Gradle在构建项目是就会检查本地是否这个库的缓存,如果没有就会联网自动下载,在添加到项目的构建目录下。
testCompile 'junit:junit:4.12' //声明测试用例库。
}