版权声明:转载请在开头注明博客原地址,谢谢! https://blog.csdn.net/qq_35928566/article/details/82285739
1.外层的build.gradle
buildscript {
repositories {
jcenter()
//这个是代码托管库,用于托管代码
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
//这里是gradle的引用,版本号为2.3.3,这是用来构建安卓项目的,
//当然了,Java、C++它也可以构建
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2.内层(APP下)的build.gradle
//这里有两个plugin可选
//1.com.android.application 2.com.android.library
//1.可以直接运行 2.只能依附于别的引用程序模块运行
apply plugin: 'com.android.application'
android {
compileSdkVersion 27 //这个是项目的sdk版本号
buildToolsVersion "28.0.2" //这个是构建项目的工具的版本
defaultConfig {
applicationId "pjk.it.bjfu.buildgradle" //项目的包的名称
minSdkVersion 24 //最低兼容的安卓版本号
targetSdkVersion 27 //你的程序在哪个版本上进行开发的,
//所有的功能在此版本上应该都是兼容的
versionCode 1 //项目的版本号
versionName "pjk_1.0" //项目的版本号对应的版本名
//以上两个属性非常重要,是应用商店判断应用有更新的重要依据
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//用于测试的工具
}
buildTypes {
release {
minifyEnabled false
//是否对项目的代码进行混淆 true是 false否
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//混淆用的文件
}
//通常会有debug和release两个闭包,顾名思义,是用来测试和线上发布的不同配置
}
}
//依赖库,大致有本地依赖(jar包)、远程依赖、和库依赖
//compile fileTree本地依赖、compile远程依赖、compile project(':helper')库依赖
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.constraint:constraint-layout:1.0.2'
//远程依赖在gradle的时候如果本地没有缓存,就会链接互联网下载,所以编译的时候需要网速好
testCompile 'junit:junit:4.12'
//测试用例的依赖
}