根目录下的build.gradle通常不需要修改这个文件中的内容,除非需要添加一些全局的项目构建配置
buildscript {repositories {google() //声明代码托管仓库Googlejcenter() //声明代码托管仓库,用于引用jcenter上的开源项目}dependencies {classpath 'com.android.tools.build:gradle:3.1.0'//声明了一个Gradle插件用来作为Android开发。3.1.0为gradle版本号}
}
allprojects {repositories {google() //声明代码托管仓库jcenter()}
}
task clean(type: Delete) {delete rootProject.buildDir
}
APP目录下的build.gradle文件是app模块的gradle构建脚本,一般用来管理app包名、版本的以及添加和修改依赖库。
apply plugin: 'com.android.application' //应用 应用程序模块android {compileSdkVersion 26 //指定使用项目的编译版本defaultConfig {applicationId "com.example.helloworld" //包名minSdkVersion 15 //指定项目最低兼容的Android版本targetSdkVersion 26 //表示Android26版本上已经进行过充分的测试versionCode 1 //项目版本号versionName "1.0" //版本名testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled false //是否进行代码混淆proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'//指定混淆规则文件}}
}dependencies {//*指定当前项目的所有依赖关系implementation fileTree(dir: 'libs', include: ['*.jar'])//本地依赖声明:将本地的jar包、目录添加依赖关系,添加到项目的构建路径当中implementation 'com.android.support:appcompat-v7:26.1.0'implementation 'com.android.support.constraint:constraint-layout:1.0.2'//远程依赖声明testImplementation 'junit:junit:4.12' //用以声明测试用例库
}