settings.gradle
用于指示 Gradle 在构建应用时应将哪些模块包含在内
include ‘:app’
build.gradle(Project:Demo)
buildscript {//这里是gradle脚本执行所需依赖,分别是对应的maven库和插件
repositories {
google()//从Android Studio3.0后新增了google()配置,可以引用google上的开源项目
jcenter()//是一个类似于github的代码托管仓库,声明了jcenter()配置,可以轻松引用 jcenter上的开源项目
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'//此处是android的插件gradle,gradle是一个强大的项目构建工具
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {//这里是项目本身需要的依赖,比如项目所需的maven库
repositories {
google()
jcenter()
}
}
// 运行gradle clean时,执行此处定义的task任务。
// 该任务继承自Delete,删除根目录中的build目录。
// 相当于执行Delete.delete(rootProject.buildDir)。
// gradle使用groovy语言,调用method时可以不用加()。
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(Moudule:app)
apply plugin: 'com.android.application'
// 声明是Android程序,
//com.android.application 表示这是一个应用程序模块
//com.android.library 标识这是一个库模块
//区别:前者可以直接运行,后着是依附别的应用程序运行
android {//配置项目构建的各种属性
compileSdkVersion 29//设置编译时用的Android版本
defaultConfig {
applicationId "com.example.lesliewang.demo"//项目的包名
minSdkVersion 15//项目最低兼容的版本
targetSdkVersion 29//项目的目标版本
versionCode 1//版本号
versionName "1.0"//版本名称
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"//表明要使用AndroidJUnitRunner进行单元测试
android.defaultConfig.vectorDrawables.useSupportLibrary = true
multiDexEnabled true//解决第三方包导入报错
}
//Error:Execution failed for task ':app:mergeDebugResources'. > Crunching Cruncher scrollbar_thumb.9.png failed, see logs
aaptOptions {
cruncherEnabled = false
useNewCruncher = false
}
buildTypes {// 生产/测试环境配置
release {// 生产环境
minifyEnabled false//是否对代码进行混淆
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'//指定混淆的规则文件
}
}
//添加jdk1.8支持
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
//打包时的相关配置
//pickFirsts做用是 当有重复文件时 打包会报错 这样配置会使用第一个匹配的文件打包进入apk
// 表示当apk中有重复的META-INF目录下有重复的LICENSE文件时 只用第一个 这样打包就不会报错
//merges何必 当出现重复文件时 合并重复的文件 然后打包入apk
//这个是有默认值得 merges = [] 这样会把默默认值去掉 所以我们用下面这种方式 在默认值后添加
packagingOptions {
//这个是在同时使用butterknife、dagger2做的一个处理。同理,遇到类似的问题,只要根据gradle的提示,做类似处理即可。
//去除重复的文件
exclude 'edu/stanford/nlp/pipeline/demo/*'
}
}
dependencies {//项目的依赖关系
implementation fileTree(include: ['*.jar'], dir: 'libs')//本地jar包依赖
implementation 'androidx.appcompat:appcompat:1.1.0'//远程依赖
implementation 'com.google.android.material:material:1.1.0'
//引入design库
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'//声明测试用例库
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation('androidx.annotation:annotation:1.0.0') {
force = true
}
implementation 'androidx.mediarouter:mediarouter:1.1.0'
//导入jar包 讯飞
implementation files('libs/Msc.jar')
implementation files('libs/Sunflower.jar')
//room
def room_version = "2.2.0-alpha01"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// Test helpers
testImplementation "androidx.room:room-testing:$room_version"
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
//nlp工具包
implementation files('libs/stanford-corenlp-3.9.2-models.jar')
implementation files('libs/stanford-corenlp-3.9.2.jar')
//解决第三方包导入报错
implementation 'com.android.support:multidex:1.0.3'
//网络请求 Retrofit库(基于okHttp封装的网络请求库)
implementation 'com.squareup.okhttp3:okhttp:4.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2' // 用Gson解析json的转换器
//百分比
implementation 'com.zhy:percent-support-extends:1.1.1'
}
gradle.properties
您可以在其中配置项目全局 Gradle 设置
# Specifies the JVM arguments used for the daemon process.用于指定守护进程的JVM参数。
# The setting is particularly useful for tweaking memory settings.这个设置呢,对于调整内存设置特别有用。
org.gradle.jvmargs=-Xmx1536m
#将依赖包也迁移到AndroidX
android.enableJetifier=true
#当前项目启用 AndroidX
android.useAndroidX=true
local.properties
配置构建系统的本地环境属性
- ndk.dir - NDK 的路径。此属性已被弃用。NDK 的所有下载版本都将安装在 Android SDK 目录下的 ndk 目录中。
- sdk.dir - SDK 的路径。
- cmake.dir - CMake 的路径。
- ndk.symlinkdir - 在 Android Studio 3.5 及更高版本中,创建指向 NDK 的符号链接,该链接可比 NDK 安装路径短。
sdk.dir=C\:\\Users\\LeslieWang\\AppData\\Local\\Android\\Sdk
gradle-wrapper.properties
#解压gradle-5.4.1-all.zip之后的文件的存放位置。
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
#下载的gradle-5.4.1-all.zip所存放的位置
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#下载的gradle的地址,使用哪个版本的gradle,就在这里修改。
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip