创建项目的时候会生成3个gradle文件
- settings.gradle
- 项目底下的build.gradle
- app包中build.gradle或其他module的gradle
settings.gradle
对于多模块开发有用
include ':app','othermodule'
项目底下的build.gradle
//实际构建会在buildscript中
buildscript {
//代码仓库,如一些依赖包
repositories {
//很有名的代码仓库
jcenter()
}
dependencies {
//定义的是gradle的安卓插件
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
//声明模块的属性
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app包中build.gradle
包含两个大模块android标签和dependencies标签,由apply plugin提供
//用到的android插件 官方提供 用于测试 打包
apply plugin: 'com.android.application'
android {
//编译apk的版本
compileSdkVersion 25
//构建的版本 aapt等工具
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.administrator.lsn_11_db"
minSdkVersion 15
targetSdkVersion 25 //表示在某些特定的版本已经通过测试了,安卓25是稳定的版本
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
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.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}