-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.gradle
162 lines (147 loc) · 5.93 KB
/
base.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
148
149
150
151
152
153
154
155
156
157
158
import sun.rmi.runtime.Log
//获取当前时间
static def getCurrentTime() {
// return new Date().format("yyyyMMddHHmmss",TimeZone.getTimeZone("UTC"))
return new Date().format("yyyyMMddHHmmss")
}
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
ext {
androidApplyPlugins = { isApp ->
if (isApp) {
apply plugin: 'com.android.application'
} else {
apply plugin: 'com.android.library'
}
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
}
androidClosure = { android, isApp, verCode, verName, appId, resourcePrefixStr->
android.with {
compileSdkVersion buildVersions.app_compile_sdk_version
buildToolsVersion buildVersions.app_build_tools_version
namespace appId
//统一资源前缀,规范资源引用
resourcePrefix resourcePrefixStr
defaultConfig {
minSdkVersion buildVersions.app_min_sdk_version
targetSdkVersion buildVersions.app_target_sdk_version
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
versionCode verCode
versionName verName
if (isApp) {
applicationId appId
}
vectorDrawables {
useSupportLibrary true
}
vectorDrawables.useSupportLibrary = true
//指定room.schemaLocation生成的文件路径
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
manifestPlaceholders = [
PACKAGE_NAME: "$appId",
]
sourceSets{
main{
if (isApp){
manifest.srcFile 'src/main/alone/AndroidManifest.xml'
}else{
manifest.srcFile 'src/main/AndroidManifest.xml'
resources {
//正式版本时,排除alone文件夹下所有调试文件
exclude 'src/main/alone/*'
}
}
}
}
/*自定义包名 aab apk*/
if (isApp){
setArchivesBaseName("${project.name}-${getCurrentTime().trim()}-V${versionName}(${versionCode})")
}
}
dexOptions {
javaMaxHeapSize "2048M"
}
kapt {
generateStubs = true //启用kapt
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose true
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
signingConfigs {
config{
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(new File(keystoreProperties['storeFile']))
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
zipAlignEnabled false //对齐zip
minifyEnabled false //开启混淆
shrinkResources false //资源缩减
multiDexEnabled true
signingConfig signingConfigs.config
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
zipAlignEnabled false
minifyEnabled false
shrinkResources false
multiDexEnabled true
signingConfig signingConfigs.config
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
dataBinding = true
viewBinding = true
compose true
}
composeOptions {
kotlinCompilerExtensionVersion kotlin_compiler_extension_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
if(isApp){
//自定义包名 apk
android.applicationVariants.all {
variant ->
variant.outputs.all {
output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
if (variant.buildType.name == 'release') {
outputFileName = "${project.name}-${getCurrentTime().trim()}-V${verName}(${verCode})-release.apk"
}else if (variant.buildType.name == 'debug') {
outputFileName = "${project.name}-${getCurrentTime().trim()}-V${verName}(${verCode})-debug.apk"
}
}
}
}
}
}
}
}