-
-
Notifications
You must be signed in to change notification settings - Fork 278
/
build.gradle.kts
103 lines (87 loc) · 3.2 KB
/
build.gradle.kts
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
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.gradle.BaseExtension
import org.jetbrains.kotlin.konan.properties.Properties
plugins {
alias(libs.plugins.kotlin) apply false
alias(libs.plugins.agp.app) apply false
alias(libs.plugins.agp.lib) apply false
alias(libs.plugins.gms) apply false
alias(libs.plugins.nav.safeargs.kotlin) apply false
}
fun String.execute(currentWorkingDir: File = file("./")): String {
val byteOut = java.io.ByteArrayOutputStream()
project.exec {
workingDir = currentWorkingDir
commandLine = split("\\s".toRegex())
standardOutput = byteOut
}
return String(byteOut.toByteArray()).trim()
}
val gitCommitCount = "git rev-list HEAD --count".execute().toInt()
val gitCommitHash = "git rev-parse --verify --short HEAD".execute()
val minSdkVer by extra(24)
val targetSdkVer by extra(35)
val buildToolsVer by extra("35.0.0")
val appVerName by extra("3.3.1")
val configVerCode by extra(90)
val serviceVerCode by extra(97)
val minBackupVerCode by extra(65)
val androidSourceCompatibility = JavaVersion.VERSION_21
val androidTargetCompatibility = JavaVersion.VERSION_21
val localProperties = Properties()
localProperties.load(file("local.properties").inputStream())
val officialBuild by extra(localProperties.getProperty("officialBuild", "false") == "true")
tasks.register("clean", Delete::class) {
delete(rootProject.layout.buildDirectory)
}
fun Project.configureBaseExtension() {
extensions.findByType<BaseExtension>()?.run {
compileSdkVersion(targetSdkVer)
buildToolsVersion = buildToolsVer
defaultConfig {
minSdk = minSdkVer
targetSdk = targetSdkVer
versionCode = gitCommitCount
versionName = appVerName
if (localProperties.getProperty("buildWithGitSuffix").toBoolean())
versionNameSuffix = ".r${gitCommitCount}.${gitCommitHash}"
consumerProguardFiles("proguard-rules.pro")
}
val config = localProperties.getProperty("fileDir")?.let {
signingConfigs.create("config") {
storeFile = file(it)
storePassword = localProperties.getProperty("storePassword")
keyAlias = localProperties.getProperty("keyAlias")
keyPassword = localProperties.getProperty("keyPassword")
}
}
buildTypes {
all {
signingConfig = config ?: signingConfigs["debug"]
}
named("release") {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = androidSourceCompatibility
targetCompatibility = androidTargetCompatibility
}
}
extensions.findByType<ApplicationExtension>()?.run {
buildTypes {
named("release") {
isShrinkResources = true
}
}
}
}
subprojects {
plugins.withId("com.android.application") {
configureBaseExtension()
}
plugins.withId("com.android.library") {
configureBaseExtension()
}
}