-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
314 lines (288 loc) · 13.6 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
ext {
// https://mvnrepository.com/artifact/androidx.room/room-compiler
// https://mvnrepository.com/artifact/androidx.room/room-runtime
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/room/room-compiler/
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/room/room-runtime/
def room_version = '2.7.0-alpha01'
// https://mvnrepository.com/artifact/com.google.dagger/hilt-android
// https://mvnrepository.com/artifact/com.google.dagger/hilt-compiler
// https://android.googlesource.com/platform/external/dagger2
def hilt_version = '2.47'
libs = [
// https://mvnrepository.com/artifact/androidx.annotation/annotation
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/annotation/annotation-jvm/
annotation : 'androidx.annotation:annotation:1.8.0-alpha01',
// https://mvnrepository.com/artifact/androidx.appcompat/appcompat
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/appcompat/appcompat/
appcompat : 'androidx.appcompat:appcompat:1.7.0-beta01',
// https://mvnrepository.com/artifact/androidx.biometric/biometric
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/biometric/biometric/
biometric : 'androidx.biometric:biometric:1.2.0-alpha05',
// https://mvnrepository.com/artifact/androidx.collection/collection
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/collection/collection-jvm/
collection : 'androidx.collection:collection:1.4.0-alpha02',
// https://mvnrepository.com/artifact/androidx.coordinatorlayout/coordinatorlayout
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/coordinatorlayout/coordinatorlayout/
coordinatorlayout : 'androidx.coordinatorlayout:coordinatorlayout:1.3.0-alpha01',
// https://mvnrepository.com/artifact/androidx.core/core
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/core/core/
core : 'androidx.core:core:1.13.0-beta01',
// https://mvnrepository.com/artifact/com.google.errorprone/error_prone_core
errorprone : 'com.google.errorprone:error_prone_core:2.30.0',
hilt_android : "com.google.dagger:hilt-android:$hilt_version",
hilt_compiler : "com.google.dagger:hilt-compiler:$hilt_version",
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-livedata
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/lifecycle/lifecycle-livedata/
livedata : 'androidx.lifecycle:lifecycle-livedata:2.8.0-alpha02',
// https://mvnrepository.com/artifact/com.google.android.material/material
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/extras/material-design-x/com/google/android/material/material/
material : 'com.google.android.material:material:1.7.0-alpha03',
// https://mvnrepository.com/artifact/androidx.preference/preference
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/preference/preference/
preference : 'androidx.preference:preference:1.2.1',
// https://mvnrepository.com/artifact/androidx.recyclerview/recyclerview
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/recyclerview/recyclerview/
recyclerview : 'androidx.recyclerview:recyclerview:1.4.0-alpha01',
room_compiler : "androidx.room:room-compiler:$room_version",
room_runtime : "androidx.room:room-runtime:$room_version",
// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-viewmodel
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/lifecycle/lifecycle-viewmodel/
viewmodel : 'androidx.lifecycle:lifecycle-viewmodel:2.8.0-alpha02'
]
}
}
plugins {
// https://mvnrepository.com/artifact/com.android.application/com.android.application.gradle.plugin
id 'com.android.application' version '8.1.4' apply false
// https://mvnrepository.com/artifact/com.android.library/com.android.library.gradle.plugin
id 'com.android.library' version '8.1.4' apply false
// https://plugins.gradle.org/plugin/org.jetbrains.kotlin.android
id 'org.jetbrains.kotlin.android' version '1.9.22' apply false
// https://mvnrepository.com/artifact/net.ltgt.errorprone/net.ltgt.errorprone.gradle.plugin
id 'net.ltgt.errorprone' version '4.0.1' apply false
// https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kover-gradle-plugin
id 'org.jetbrains.kotlinx.kover' version '0.8.3' apply false
}
allprojects {
plugins.withType(JavaBasePlugin).configureEach {
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
}
ext {
addCompileOnlyJar = { String name ->
final def jars_dir = "$rootDir/prebuilts/jars"
final def jar = new File(jars_dir, name)
if (!jar.exists()) {
throw new IllegalArgumentException("Cannot find prebuilt '${jar.path}' file.")
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile).configureEach {
classpath = files(jar, classpath)
}
tasks.withType(KotlinCompile).configureEach {
libraries.from(files(jar))
}
}
dependencies {
compileOnly files(jar)
}
}
}
}
apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'kotlin-kapt'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'org.jetbrains.kotlinx.kover'
final def versionNameCommon = [file('version.txt').text.trim()]
if (System.getenv('EXTRA_VERSION_BUILD_INFO') == null) {
final def tag = 'v' + versionNameCommon[0]
final def (semver, commitsSinceLastTag, headCommit) = gitDescribeTag(tag, 'HEAD')
versionNameCommon.add('git branch --show-current'.execute([], project.rootDir).text.trim())
versionNameCommon.add(String.format('%s+%s', headCommit, commitsSinceLastTag))
} else {
final def extraVersionBuildInfo = System.getenv('EXTRA_VERSION_BUILD_INFO').trim()
if (!extraVersionBuildInfo.isEmpty()) {
versionNameCommon.add(extraVersionBuildInfo)
}
}
android {
namespace 'com.github.iusmac.sevensim'
buildToolsVersion = '34.0.0'
defaultConfig {
applicationId 'com.github.iusmac.sevensim'
targetSdk 34
versionCode versionNameCommon[0].replaceAll(/\D/, '') as Integer // "x.y.z" => xyz
}
applicationVariants.all { variant ->
final def versionNameVariant = versionNameCommon.clone()
if (variant.buildType.isDebuggable()) {
versionNameVariant.add('DEBUG')
} else if (isReleaseDebugOpt()) {
versionNameVariant.add('DEBUG-OPT')
}
variant.outputs.each { output ->
final def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
final semVer = versionNameCommon[0]
output.outputFileName = String.format('%s-%s-%s.apk', project.name, semVer,
variant.buildType.name)
}
output.versionNameOverride = versionNameVariant.join(' / ')
}
}
final def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(file('keystore.properties')))
def releaseSigning = signingConfigs.create('release') {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
buildTypes {
all {
buildConfigField 'boolean', 'DEBUG_OPT', 'false'
signingConfig releaseSigning
}
release {
buildConfigField 'boolean', 'DEBUG_OPT', isReleaseDebugOpt().toString()
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard.flags'
}
}
sourceSets {
main {
java.srcDirs = ['src']
res.srcDirs = ['res']
manifest.srcFile 'AndroidManifest.xml'
}
}
lint {
// Instead of failing the build due to missing translations, just inform us to avoid
// mistakes during manual import
informational 'MissingTranslation'
}
dependenciesInfo {
includeInApk = false
includeInBundle = false
}
packagingOptions.resources.excludes += [
"**/*.bin",
"**/*.properties",
"**/*.version",
"kotlin/**",
"META-INF/services/**",
"META-INF/com/**",
]
tasks.withType(JavaCompile) {
options.errorprone {
enabled = true
disableWarningsInGeneratedCode = true // for @Generated (e.g., Dagger/Hilt, Room)
excludedPaths = '.*/build/generated/.*' // for other generated code
}
}
}
addCompileOnlyJar('android-34.jar')
dependencies {
implementation libs.annotation
implementation libs.biometric
implementation libs.collection
implementation libs.core
implementation libs.livedata
implementation libs.material
implementation libs.preference
implementation libs.recyclerview
implementation libs.viewmodel
implementation libs.hilt_android
kapt libs.hilt_compiler
implementation libs.room_runtime
kapt libs.room_compiler
implementation project(path: ':SettingsLib:BannerMessagePreference')
implementation project(path: ':SettingsLib:CollapsingToolbarBaseActivity')
implementation project(path: ':SettingsLib:LayoutPreference')
implementation project(path: ':SettingsLib:SettingsTheme')
implementation project(path: ':SettingsLib:TwoTargetPreference')
errorprone libs.errorprone
annotationProcessor libs.errorprone
}
kapt {
correctErrorTypes true
}
kover {
reports {
filters {
excludes {
// excludes class by fully-qualified JVM class name, wildcards
// '*' and '?' are available
classes(
'*BuildConfig',
// '*\$Factory',
'*.Hilt_*',
'*_ComponentTreeDeps',
'*_HiltComponents*',
'*_Impl',
'*_Impl\$*',
)
// excludes all classes located in specified package and it
// subpackages, wildcards '*' and '?' are available
packages(
'com.github.iusmac.sevensim.inject',
'hilt_aggregated_deps',
'dagger.hilt.internal.*',
)
// excludes all classes and functions, annotated by specified
// annotations, wildcards '*' and '?' are available
annotatedBy('*Generated*')
annotatedBy('*AssistedFactory')
}
}
}
}
/**
* Describe the tag relative to a commit-ish using "git describe".
*
* The result from the git describe command will be transformed as follows:
* "TAG-N-g<commit-ish>" = ["TAG", "N", "commit-ish"]
* "<commit-ish>" = [null, 0, "commit-ish"]
*/
def gitDescribeTag(final String pattern, final String commitIsh) {
final def describedTag = String.format('git describe --always --tags --long --match=%s %s',
pattern, commitIsh).execute([], project.rootDir).text.trim().split('-')
final def tag, commitsSinceLastTag
def headCommit
if (describedTag.size() > 2) {
tag = describedTag[0..-3].join('-')
(commitsSinceLastTag, headCommit) = describedTag[-2..-1]
headCommit = headCommit.substring(1)
} else if (describedTag.size() > 0) {
tag = null
headCommit = describedTag[0]
commitsSinceLastTag = 0
assert(headCommit != null && !headCommit.trim().isEmpty())
} else {
throw new AssertionError('The output from `git describe` command is empty.')
}
return [tag, commitsSinceLastTag, headCommit]
}
/**
* Check whether it was asked to opt-in for debug logging on releases with R8.
*
* The output of this function is determined via:
* - Gradle argument: -PreleaseDebugOpt=[true|false]
* - Environment variable: RELEASE_DEBUG_OPT=[true|false]
*
* Boolean as Integer is allowed.
*/
def isReleaseDebugOpt() {
final def String debugOpt = [
System.getenv('RELEASE_DEBUG_OPT'),
project.properties.releaseDebugOpt
]
return debugOpt.contains('1') || debugOpt.contains('true')
}