-
-
Notifications
You must be signed in to change notification settings - Fork 309
Expand file tree
/
Copy pathbuild.gradle
More file actions
478 lines (414 loc) · 19.1 KB
/
Copy pathbuild.gradle
File metadata and controls
478 lines (414 loc) · 19.1 KB
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
import com.android.build.api.variant.FilterConfiguration
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
plugins {
id 'com.android.application'
id 'com.google.devtools.ksp'
}
// apply Google Services and Firebase Crashlytics plugins conditionally
// strategy: For command-line builds, check task names. For IDE, always apply plugins
// but they'll only process play/website variants (Firebase deps are scoped to those variants)
def taskNames = gradle.startParameter.taskNames.join(',').toLowerCase()
def apkBuild = taskNames.contains("full")
def fdroidBuild = taskNames.contains("fdroid")
// for alpha builds generate universal apk only
def alphaBuild = taskNames.contains("alpha")
// check for fdroidserver value is set in system env
def fdroidBuildServer = System.getenv("fdroidserver")
def isFdroidBuildServer = fdroidBuildServer != null && !fdroidBuildServer.isEmpty() && fdroidBuildServer != "null"
def deGoogled = !apkBuild || fdroidBuild || isFdroidBuildServer
def shouldSplit = !alphaBuild
println("app-task names: '$taskNames'")
println("gradle deGoogled? $deGoogled (fdroidBuild: $fdroidBuild, fdroidBuildServer: $isFdroidBuildServer, apkBuild: $apkBuild)")
println("gradle alphaBuild? $alphaBuild, should split? $shouldSplit")
// don't apply firebase plugins for fdroid CLI builds
if (!deGoogled) {
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
println("app firebase plugins applied")
} else {
println("app firebase plugins SKIPPED")
}
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
// https://github.com/celzero/rethink-app/issues/1032
// https://docs.gradle.org/8.2/userguide/configuration_cache.html#config_cache:requirements:external_processes
// get the git version from the command line
def gitVersion = providers.exec {
commandLine("git", "describe", "--tags", "--always")
}.standardOutput.asText.get().toString().trim()
// for github builds, the version code is set in the github action via env
// for local builds, the version code is set in gradle.properties
def getVersionCode = {
def code = 0
try {
// parseInt throws NumberFormatException if the string does not contain a parsable integer
// but "as Integer" is a wrapper class, which silently returns null
code = Integer.parseInt(System.getenv("VERSION_CODE"))
logger.info("env version code: $code")
} catch (NumberFormatException ex) {
logger.info("missing env version code: $ex.message")
}
if (code == 0) {
code = project.properties['VERSION_CODE'] as Integer
logger.info("project properties version code: $code")
}
return code
}
try {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
} catch (Exception ex) {
logger.info("missing keystore prop: $ex.message")
keystoreProperties['keyAlias'] = ''
keystoreProperties['keyPassword'] = ''
keystoreProperties['storeFile'] = '/dev/null'
keystoreProperties['storePassword'] = ''
}
// ref: developer.android.com/build/jdks#target-compat
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
android {
compileSdkVersion(36)
// https://developer.android.com/studio/build/configure-app-module
namespace 'com.celzero.bravedns'
defaultConfig {
applicationId "com.celzero.bravedns"
minSdkVersion(23)
targetSdkVersion 35
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
config {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
// archive.is/wlwD8
alpha {
keyAlias System.getenv("ALPHA_KS_ALIAS") // rdnsAlpha
keyPassword System.getenv("ALPHA_KS_PASSPHRASE")
// https://stackoverflow.com/a/34640602
storeFile file(String.valueOf(System.getenv("ALPHA_KS_FILE"))) // rdnsAlpha.jks in app/
storePassword System.getenv("ALPHA_KS_STORE_PASSPHRASE")
}
}
// https://developer.android.com/studio/build/configure-apk-splits
// alpha builds produce a single universal apk
// release builds produce split apk and universal apk
splits.abi {
if (!shouldSplit) {
println('universal apk only (splits disabled)')
enable false
} else {
println('split apks and universal apk (splits enabled)')
enable true
reset()
// comma-separated list of ABIs to generate apks for
include 'x86', 'armeabi-v7a', 'arm64-v8a', 'x86_64'
// generates a universal APK in addition to per-ABI apks
universalApk true
}
}
// version codes for each ABI variant
project.ext.versionCodes = [
'armeabi-v7a': 2,
'arm64-v8a' : 3,
'x86' : 8,
'x86_64' : 9
]
androidComponents {
onVariants(selector().all()) { variant ->
variant.outputs.each { output ->
def abi = output.filters.find { it.filterType == FilterConfiguration.FilterType.ABI }?.identifier
if (abi != null) {
// ABI-specific output: assign the correct per-ABI version code
// eg for arm64-v8a: 3 * 10000000 + versionCode
def v = project.ext.versionCodes.get(abi) * 10000000 + output.versionCode.get()
output.versionCode.set(v)
} else {
// universal APK: preserve existing production behaviour (arm64-v8a multiplier)
// so installed universal APKs are not treated as a downgrade
// when splits are disabled (e.g. alpha builds), firstAbi is null; fall back to
// the arm64-v8a multiplier (3) so versionCode arithmetic still works
def firstAbi = variant.outputs.find { it.filters.any { f -> f.filterType == FilterConfiguration.FilterType.ABI } }
?.filters?.find { it.filterType == FilterConfiguration.FilterType.ABI }?.identifier
def multiplier = firstAbi != null ? project.ext.versionCodes.get(firstAbi) : project.ext.versionCodes.get('arm64-v8a')
def v = multiplier * 10000000 + output.versionCode.get()
output.versionCode.set(v)
}
}
}
}
buildTypes {
release {
// modified as part of #352, now webview is removed from app, flipping back
// the setting to true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
ndk {
// Use SYMBOL_TABLE to reduce symbol file size significantly
debugSymbolLevel 'SYMBOL_TABLE'
// Only process symbols for the most common ABIs to avoid Crashlytics index errors
// This reduces the total symbol data Crashlytics needs to process
abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86_64'
}
if (!deGoogled) {
firebaseCrashlytics {
// Enable processing and uploading of native symbols to Firebase servers.
nativeSymbolUploadEnabled true
}
}
}
leakCanary {
matchingFallbacks = ['debug']
initWith buildTypes.debug
}
alpha {
// archive.is/y8uCB
applicationIdSuffix ".alpha"
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.alpha
resValue "string", "app_name", "Rethink(α)"
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
// fix: injectCrashlyticsBuildIds task has a buffer overflow bug
// apply crashlytics configuration to firebase builds only
if (!deGoogled) {
// workaround for crashlytics gradle plugin bug with large native symbols
afterEvaluate {
tasks.configureEach { task ->
if (task.name.contains("injectCrashlyticsBuildIds")) {
// disable the problematic task - symbols will still be uploaded via uploadCrashlyticsSymbolFile
task.enabled = false
logger.warn("disabled build id injection for: ${task.name} (workaround for IndexOutOfBoundsException)")
logger.warn("native symbols will still be uploaded via uploadCrashlyticsSymbolFile task")
}
if (task.name.contains("uploadCrashlyticsSymbolFile")) {
task.doFirst {
logger.info("uploading crashlytics symbols: ${task.name}")
}
}
}
}
}
kotlin {
compilerOptions {
languageVersion = KotlinVersion.KOTLIN_2_3
jvmTarget = JvmTarget.JVM_17
freeCompilerArgs.addAll([
'-Xsuppress-warning=SENSELESS_COMPARISON'
])
}
}
buildFeatures {
viewBinding true
buildConfig true
resValues true
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
packagingOptions {
jniLibs {
keepDebugSymbols += ['**/*.so']
}
}
// required for google play developer api model classes
packaging {
resources.excludes += "META-INF/INDEX.LIST"
}
flavorDimensions = ["releaseChannel", "releaseType"]
productFlavors {
play {
dimension "releaseChannel"
}
fdroid {
dimension "releaseChannel"
}
website {
dimension "releaseChannel"
}
full {
dimension "releaseType"
// getPackageInfo().versionCode not returning the correct value (in prod builds) when
// value is set in AndroidManifest.xml so setting it here
// for build type alpha, versionCode is set in env overriding gradle.properties
versionCode = getVersionCode()
versionName = gitVersion
vectorDrawables.useSupportLibrary = true
}
}
lint {
abortOnError true
}
}
configurations {
download {
transitive false
}
}
def firestackRepo = project.findProperty("firestackRepo") ?: "github"
def firestackCommit = project.findProperty("firestackCommit") ?: "main"
def firestackDependency = { ->
switch (firestackRepo) {
case "jitpack":
return "com.github.celzero:firestack:$firestackCommit@aar"
case "github":
return "com.github.celzero:firestack:$firestackCommit@aar"
case "ossrh":
return "com.celzero:firestack:$firestackCommit@aar"
default:
throw new GradleException("Unknown firestackRepo: $firestackRepo")
}
}
dependencies {
def room_version = "2.8.4"
def paging_version = "3.5.0"
implementation 'com.google.guava:guava:33.6.0-android'
// https://developer.android.com/studio/write/java8-support
// included to fix issues with Android 6 support, issue#563
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")
fullImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.3.21'
fullImplementation 'androidx.appcompat:appcompat:1.7.1'
fullImplementation 'androidx.core:core-ktx:1.19.0'
implementation 'androidx.preference:preference-ktx:1.2.1'
fullImplementation 'androidx.constraintlayout:constraintlayout:2.2.1'
fullImplementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.2.0'
fullImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0'
fullImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.11.0'
// LiveData
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.10.0'
implementation 'com.google.code.gson:gson:2.14.0'
implementation "androidx.room:room-runtime:$room_version"
ksp "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
implementation "androidx.room:room-paging:$room_version"
fullImplementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.10.0'
fullImplementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.10.0'
// Pagers Views
implementation "androidx.paging:paging-runtime-ktx:$paging_version"
fullImplementation 'androidx.fragment:fragment-ktx:1.8.9'
implementation 'com.google.android.material:material:1.14.0'
fullImplementation 'androidx.viewpager2:viewpager2:1.1.0'
fullImplementation 'com.squareup.okhttp3:okhttp:5.3.2'
fullImplementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:5.3.2'
fullImplementation 'com.squareup.okhttp3:logging-interceptor:5.3.2'
fullImplementation 'com.squareup.retrofit2:retrofit:3.0.0'
fullImplementation 'com.squareup.retrofit2:converter-gson:3.0.0'
implementation 'com.squareup.okio:okio-jvm:3.17.0'
// Glide
fullImplementation('com.github.bumptech.glide:glide:5.0.7') {
exclude group: 'glide-parent'
}
fullImplementation('com.github.bumptech.glide:okhttp3-integration:5.0.7') {
exclude group: 'glide-parent'
}
// Ref: https://stackoverflow.com/a/46638213
kspFull 'com.github.bumptech.glide:compiler:5.0.7'
// Swipe button animation
fullImplementation 'com.facebook.shimmer:shimmer:0.5.0'
// Koin core
download 'io.insert-koin:koin-core:4.2.1'
implementation 'io.insert-koin:koin-core:4.2.1'
// Koin main (Scope, ViewModel ...)
download 'io.insert-koin:koin-android:4.2.1'
implementation 'io.insert-koin:koin-android:4.2.1'
download 'hu.autsoft:krate:2.0.0'
implementation 'hu.autsoft:krate:2.0.0'
// viewBinding without reflection
fullImplementation 'com.github.kirich1409:viewbindingpropertydelegate:1.5.9'
fullImplementation 'com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.9'
// add ":debug" suffix to the dependency to include debug symbols
download firestackDependency()
websiteImplementation firestackDependency()
fdroidImplementation firestackDependency()
playImplementation firestackDependency()
// Work manager
implementation('androidx.work:work-runtime-ktx:2.11.2') {
modules {
module("com.google.guava:listenablefuture") {
replacedBy("com.google.guava:guava", "listenablefuture is part of guava")
}
}
}
// for handling IP addresses and subnets, both IPv4 and IPv6
// seancfoley.github.io/IPAddress/ipaddress.html
download 'com.github.seancfoley:ipaddress:5.6.2'
implementation 'com.github.seancfoley:ipaddress:5.6.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
androidTestImplementation 'androidx.test:rules:1.7.0'
testImplementation 'org.robolectric:robolectric:4.16.1'
testImplementation 'androidx.test:core:1.7.0'
testImplementation 'androidx.test.ext:junit:1.3.0'
testImplementation 'org.mockito:mockito-core:5.23.0'
// Added test dependencies for comprehensive testing
testImplementation 'io.mockk:mockk:1.14.11'
testImplementation 'io.mockk:mockk-android:1.14.11'
testImplementation 'androidx.arch.core:core-testing:2.2.0'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.11.0'
testImplementation 'io.insert-koin:koin-test:4.2.1'
testImplementation 'io.insert-koin:koin-test-junit4:4.2.1'
androidTestImplementation 'io.mockk:mockk-android:1.14.11'
leakCanaryImplementation 'com.squareup.leakcanary:leakcanary-android:2.14'
fullImplementation 'androidx.navigation:navigation-fragment-ktx:2.9.8'
fullImplementation 'androidx.navigation:navigation-ui-ktx:2.9.8'
fullImplementation 'androidx.biometric:biometric:1.1.0'
playImplementation 'com.google.android.play:app-update:2.1.0'
playImplementation 'com.google.android.play:app-update-ktx:2.1.0'
// for encrypting wireguard configuration files
implementation("androidx.security:security-crypto:1.1.0")
implementation("androidx.security:security-app-authenticator:1.0.0")
androidTestImplementation("androidx.security:security-app-authenticator:1.0.0")
// barcode scanner for wireguard
fullImplementation 'com.journeyapps:zxing-android-embedded:4.3.0'
fullImplementation 'com.simplecityapps:recyclerview-fastscroll:2.0.1'
// for confetti animation
fullImplementation 'nl.dionsegijn:konfetti-xml:2.0.5'
constraints {
implementation("androidx.annotation:annotation-experimental:1.6.0")
}
// for in-app purchases
playImplementation 'com.android.billingclient:billing:8.3.0'
websiteImplementation 'com.android.billingclient:billing:8.3.0'
// for stripe payment gateway
//websiteImplementation 'com.stripe:stripe-android:21.21.0'
//fdroidImplementation 'com.stripe:stripe-android:21.21.0'
// google play developer api model classes (ProductPurchaseV2, SubscriptionPurchaseV2, …)
// Only model classes + GsonFactory are needed, Apache HTTP transport is excluded.
// The version v3-rev20240301-2.0.0 cited in the API docs does not exist on Maven Central;
// v3-rev20260318-2.0.0 is the closest available release with the same model classes.
// ref: github.com/googleapis/google-api-java-client-services/tree/main/clients/google-api-services-androidpublisher/v3
playImplementation('com.google.apis:google-api-services-androidpublisher:v3-rev20260318-2.0.0') {
// Exclude Apache HTTP transport, conflicts with Android's built-in HTTP stack
exclude group: 'com.google.http-client', module: 'google-http-client-apache-v2'
exclude group: 'org.apache.httpcomponents'
// Exclude OAuth, not needed for model-only parsing
exclude group: 'com.google.oauth-client'
}
websiteImplementation('com.google.apis:google-api-services-androidpublisher:v3-rev20260318-2.0.0') {
exclude group: 'com.google.http-client', module: 'google-http-client-apache-v2'
exclude group: 'org.apache.httpcomponents'
exclude group: 'com.google.oauth-client'
}
lintChecks 'com.android.security.lint:lint:1.0.4'
// battery optimization permission helper
implementation 'com.waseemsabir:betterypermissionhelper:1.0.3'
// Firebase dependencies for error reporting (website and play variants only)
websiteImplementation platform('com.google.firebase:firebase-bom:34.14.1')
websiteImplementation 'com.google.firebase:firebase-crashlytics'
websiteImplementation 'com.google.firebase:firebase-crashlytics-ndk'
playImplementation platform('com.google.firebase:firebase-bom:34.14.1')
playImplementation 'com.google.firebase:firebase-crashlytics'
playImplementation 'com.google.firebase:firebase-crashlytics-ndk'
}