-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
147 lines (133 loc) · 8.38 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
plugins {
id 'com.android.application'// 提供了Android 编译、测试、打包等等的所有task。
id 'kotlin-android'
id 'kotlin-kapt'
}
// 是Android插件提供的一个扩展类型,可以让我们自定义Android Gradle工程,是Android Gradle工程配置的唯一入口。
android {
// minSdkVersion<=targetSdkVersion<=compileSdkVersion
// compileSdkVersion和buildToolsVersion作用于项目的编译,minSdkVersion和targetSdkVersion控制项目的运行版本。
// 代表着编译的时候,会采用该api的规范进行代码检查和警告,但是并不会编译进apk中。
// 强烈推荐总是使用最新的 SDK 进行编译(默认就是最新的),好处如下:
// 1、可以让我们在编码的过程中编译器以最新的SDK的api去要求我们的编码,即让你可以调用高版本的api;
// 2、它会有最新的一些编译警告、编译错误提示,这样可以避免弃用的API,并且为使用新的API做好准备;
// 3、当我们的项目有其他第三方sdk或者supperLib时,compileSdkVersion低于这些库的编译版本时就无法编译打包。
// 注意:如果使用 Support Library ,那么使用最新发布的 Support Library 就需要使用最新的 SDK 编译。
compileSdkVersion 31
// defaultConfig就是程序的默认配置,注意,如果在AndroidMainfest.xml里面定义了与这里相同的属性,会以这里的为主。
// 默认的配置,它是一个ProductFlavor。ProductFlavor允许我们根据不同的情况同时生成多个不同的apk包。
defaultConfig {
// applicationId 配置我们的包名,包名是app的唯一标识,其实他跟AndroidManifest里面的package是可以不同的,他们之间并没有直接的关系。
// package指的是代码目录下路径;applicationId指的是app对外发布的唯一标识,会在签名、申请第三方库、发布时候用到。
// 修改applicationId只会修改当前程序的ID,而不会去修改源码中资源文件的引用。
applicationId "com.tgf.kcwc"
// 代表着最低版本,在编译的时候兼容到该参数指定最低版本api。
// 如果系统的API level低于android:minSdkVersion设定的值,那么android系统会阻止用户安装这个应用
// 请记住:你所使用的库,如 Support Library 或 Google Play services,可能有他们自己的 minSdkVersion 。你的应用设置的
// minSdkVersion 必需大于等于这些库的 minSdkVersion 。
minSdkVersion 19
// 代表着目标版本,在编译的时候会将该版本的api编译进apk中。
// 建议设置为最新的版本最好,因为不需要让系统对app进行前向兼容了,提高了性能,同时也可以使用高版本的一些新特性。
// 决定了Android系统的运行版本,是 Android 提供向前兼容的主要依据
// 比如说我设置了targetSdkVersion=22,那么运行在23的手机上,不会有任何问题,只是不能享受23的新功能。即由系统自动向下兼容了,因为23的手机上包含低于它的api。
// 比如说我设置了targetSdkVersion=22,那么运行在21的手机上,会有问题,因为开发使用的22的api,在21上根本没有,所以需要在代码中判断版本进行兼容,如:if(targetSdkVersion<22){}。
targetSdkVersion 31
// 表明我们的app应用内部版本号,一般用于控制app升级,当然我在使用的bugly自动升级能不能接受到升级推送就是基于这个。
versionCode 1
// 表明我们的app应用的版本名称,一般是发布的时候写在app上告诉用户的
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// 用于配置该BuildType是否启用自动拆分多个Dex的功能。一般用程序中代码太多,超过了65535个方法的时候。
// 配置了 multiDexEnabled true 后,会自动添加引用:androidx.multidex:multidex:2.0.0 和 androidx.multidex:multidex-instrumentation:2.0.0
// api 21以下,还需要在 Application 的 attachBaseContext 方法中添加初始化代码:MultiDex.install(this),或者直接继承 MultiDexApplication。否则会报错:Unable to get provider androidx.lifecycle.ProcessLifecycleOwnerInitializr
multiDexEnabled true
}
lintOptions {
disable 'GoogleAppIndexingWarning'// 解决AndroidManifest.xml警告。
}
// 签名配置,一个app只有在签名之后才能被发布、安装、使用
signingConfigs {
// storeFile签名文件,
// storePassword签名证书文件的密码,
// storeType签名证书类型,
// keyAlias签名证书中秘钥别名,
// keyPassword签名证书中改密钥的密码。
release {
storeFile file("../like.jks")
storePassword "like5488"
keyAlias "like"
keyPassword "like5488"
}
}
/**
* 定义了编译类型,针对每个类型我们可以有不同的编译配置,不同的编译配置对应的有不同的编译命令。
* 默认内置了debug和release两个构建类型,两种模式主要车别在于,能否在设备上调试以及签名不一样
*
* name:build type的名字
* applicationIdSuffix:应用id后缀
* versionNameSuffix:版本名称后缀
* debuggable:是否生成一个debug的apk
* minifyEnabled:是否混淆
* proguardFiles:混淆文件
* signingConfig:签名配置
* manifestPlaceholders:清单占位符
* shrinkResources:是否去除未利用的资源,默认false,表示不去除。
* zipAlignEnable:是否使用zipalign工具压缩。
* multiDexEnabled:是否拆成多个Dex
* multiDexKeepFile:指定文本文件编译进主Dex文件中
* multiDexKeepProguard:指定混淆文件编译进主Dex文件中
*/
buildTypes {
release {
minifyEnabled true
zipAlignEnabled true
shrinkResources true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled true
}
// 解决Invoke-customs are only supported starting with Android O
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
//More than one file was found with OS independent path 'META-INF/core_release.kotlin_module'
packagingOptions {
exclude 'META-INF/*.kotlin_module'
}
}
// 定义了当前项目需要依赖的其他库。
dependencies {
// gradlew app:dependencies --configuration releaseCompileClasspath 查看依赖树
// 这样配置之后本地libs文件夹下的扩展名为jar的都会被依赖,非常方便。
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
implementation 'com.google.android:flexbox:2.0.1'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'androidx.activity:activity-ktx:1.4.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
implementation 'com.github.getActivity:ToastUtils:9.5'
implementation 'org.koin:koin-androidx-viewmodel:2.2.2'
implementation 'io.coil-kt:coil:1.4.0'
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
implementation 'com.shouzhong:Scanner:1.1.3'
implementation 'com.shouzhong:ScannerIdCardLib:1.0.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.amap.api:location:latest.integration'
implementation 'io.github.lucksiege:pictureselector:v2.7.3-rc05'
implementation project(':common')
}