-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathbuild.gradle.kts
385 lines (333 loc) · 14 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
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
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import com.android.build.gradle.internal.lint.LintModelWriterTask
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.android.build.gradle.tasks.MergeSourceSetFolders
import java.io.FileInputStream
import java.util.Properties
import org.gradle.configurationcache.extensions.capitalized
plugins {
id(Dependencies.Plugin.androidApplicationId)
id(Dependencies.Plugin.playPublisherId)
id(Dependencies.Plugin.kotlinAndroidId)
id(Dependencies.Plugin.kotlinParcelizeId)
id(Dependencies.Plugin.ksp) version Versions.Plugin.ksp
id(Dependencies.Plugin.junit5) version Versions.Plugin.junit5
id(Dependencies.Plugin.composeCompiler) version Versions.kotlin
}
val repoRootPath = rootProject.projectDir.absoluteFile.parentFile.absolutePath
val extraAssetsDirectory = "${project.buildDir}/extraAssets"
val defaultChangelogAssetsDirectory = "$repoRootPath/android/src/main/play/release-notes/"
val extraJniDirectory = "${project.buildDir}/extraJni"
val credentialsPath = "${rootProject.projectDir}/credentials"
val keystorePropertiesFile = file("$credentialsPath/keystore.properties")
val keystoreProperties = Properties()
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}
android {
namespace = "net.mullvad.mullvadvpn"
compileSdk = Versions.Android.compileSdkVersion
defaultConfig {
val localProperties = gradleLocalProperties(rootProject.projectDir, providers)
applicationId = "net.mullvad.mullvadvpn"
minSdk = Versions.Android.minSdkVersion
targetSdk = Versions.Android.targetSdkVersion
versionCode = generateVersionCode(localProperties)
versionName = generateVersionName(localProperties)
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
lint {
lintConfig = file("${rootProject.projectDir}/config/lint.xml")
baseline = file("lint-baseline.xml")
abortOnError = true
warningsAsErrors = true
}
}
androidResources {
@Suppress("UnstableApiUsage")
generateLocaleConfig = true
}
if (keystorePropertiesFile.exists()) {
signingConfigs {
create(SigningConfigs.RELEASE) {
storeFile = file("$credentialsPath/app-keys.jks")
storePassword = keystoreProperties.getProperty("storePassword")
keyAlias = keystoreProperties.getProperty("keyAlias")
keyPassword = keystoreProperties.getProperty("keyPassword")
}
}
}
buildTypes {
getByName(BuildTypes.RELEASE) {
signingConfig = signingConfigs.findByName(SigningConfigs.RELEASE)
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
create(BuildTypes.FDROID) {
initWith(buildTypes.getByName(BuildTypes.RELEASE))
signingConfig = null
matchingFallbacks += BuildTypes.RELEASE
}
create(BuildTypes.LEAK_CANARY) {
initWith(buildTypes.getByName(BuildTypes.DEBUG))
applicationIdSuffix = ".leakcanary"
matchingFallbacks += BuildTypes.DEBUG
}
}
flavorDimensions += FlavorDimensions.BILLING
flavorDimensions += FlavorDimensions.INFRASTRUCTURE
productFlavors {
create(Flavors.OSS) {
dimension = FlavorDimensions.BILLING
isDefault = true
}
create(Flavors.PLAY) { dimension = FlavorDimensions.BILLING }
create(Flavors.PROD) {
dimension = FlavorDimensions.INFRASTRUCTURE
isDefault = true
}
create(Flavors.DEVMOLE) {
dimension = FlavorDimensions.INFRASTRUCTURE
applicationId = "net.mullvad.mullvadvpn.devmole"
}
create(Flavors.STAGEMOLE) {
dimension = FlavorDimensions.INFRASTRUCTURE
applicationId = "net.mullvad.mullvadvpn.stagemole"
}
}
sourceSets {
getByName("main") {
val changelogDir =
gradleLocalProperties(rootProject.projectDir, providers)
.getOrDefault("OVERRIDE_CHANGELOG_DIR", defaultChangelogAssetsDirectory)
assets.srcDirs(extraAssetsDirectory, changelogDir)
jniLibs.srcDirs(extraJniDirectory)
}
}
buildFeatures {
compose = true
buildConfig = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
allWarningsAsErrors = false
jvmTarget = Versions.jvmTarget
freeCompilerArgs =
listOf(
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=kotlinx.coroutines.ObsoleteCoroutinesApi",
// Opt-in option for Koin annotation of KoinComponent.
"-opt-in=kotlin.RequiresOptIn"
)
}
tasks.withType<MergeSourceSetFolders> { dependsOn(getTasksByName("copyExtraAssets", true)) }
tasks.withType<LintModelWriterTask> { dependsOn(getTasksByName("copyExtraAssets", true)) }
// Suppressing since we don't seem have much of an option than using this api. The impact should
// also be limited to tests.
@Suppress("UnstableApiUsage")
testOptions {
unitTests.all { test ->
test.testLogging {
test.outputs.upToDateWhen { false }
events("passed", "skipped", "failed", "standardOut", "standardError")
showCauses = true
showExceptions = true
}
}
}
packaging {
jniLibs.useLegacyPackaging = true
resources {
pickFirsts +=
setOf(
// Fixes packaging error caused by: androidx.compose.ui:ui-test-junit4
"META-INF/AL2.0",
"META-INF/LGPL2.1",
// Fixes packaging error caused by: jetified-junit-*
"META-INF/LICENSE.md",
"META-INF/LICENSE-notice.md",
"META-INF/io.netty.versions.properties",
"META-INF/INDEX.LIST"
)
}
}
applicationVariants.configureEach {
val alwaysShowChangelog =
gradleLocalProperties(rootProject.projectDir, providers)
.getProperty("ALWAYS_SHOW_CHANGELOG") ?: "false"
buildConfigField("boolean", "ALWAYS_SHOW_CHANGELOG", alwaysShowChangelog)
val enableInAppVersionNotifications =
gradleLocalProperties(rootProject.projectDir, providers)
.getProperty("ENABLE_IN_APP_VERSION_NOTIFICATIONS") ?: "true"
buildConfigField(
"boolean",
"ENABLE_IN_APP_VERSION_NOTIFICATIONS",
enableInAppVersionNotifications
)
}
applicationVariants.all {
val artifactSuffix = buildString {
productFlavors.getOrNull(0)?.name?.let { billingFlavorName ->
if (billingFlavorName != Flavors.OSS) {
append(".$billingFlavorName")
}
}
productFlavors.getOrNull(1)?.name?.let { infrastructureFlavorName ->
if (infrastructureFlavorName != Flavors.PROD) {
append(".$infrastructureFlavorName")
}
}
if (buildType.name != BuildTypes.RELEASE) {
append(".${buildType.name}")
}
}
val variantName = name
val capitalizedVariantName = variantName.capitalized()
val artifactName = "MullvadVPN-${versionName}${artifactSuffix}"
tasks.register<Copy>("create${capitalizedVariantName}DistApk") {
from(packageApplicationProvider)
into("${rootDir.parent}/dist")
include { it.name.endsWith(".apk") }
rename { "$artifactName.apk" }
}
val createDistBundle =
tasks.register<Copy>("create${capitalizedVariantName}DistBundle") {
from("$buildDir/outputs/bundle/$variantName")
into("${rootDir.parent}/dist")
include { it.name.endsWith(".aab") }
rename { "$artifactName.aab" }
}
createDistBundle.dependsOn("bundle$capitalizedVariantName")
}
project.tasks.assemble.dependsOn("ensureJniDirectoryExist")
project.tasks.assemble.dependsOn("ensureValidVersionCode")
}
junitPlatform {
instrumentationTests {
version.set(Versions.Android.junit)
includeExtensions.set(true)
}
}
composeCompiler { enableStrongSkippingMode = true }
androidComponents {
beforeVariants { variantBuilder ->
variantBuilder.enable =
variantBuilder.let { currentVariant ->
val enabledVariants =
enabledAppVariantTriples.map { (billing, infra, buildType) ->
billing + infra.capitalized() + buildType.capitalized()
}
enabledVariants.contains(currentVariant.name)
}
}
}
configure<org.owasp.dependencycheck.gradle.extension.DependencyCheckExtension> {
// Skip the lintClassPath configuration, which relies on many dependencies that has been flagged
// to have CVEs, as it's related to the lint tooling rather than the project's compilation class
// path. The alternative would be to suppress specific CVEs, however that could potentially
// result in suppressed CVEs in project compilation class path.
skipConfigurations = listOf("lintClassPath")
}
tasks.register("copyExtraAssets", Copy::class) {
from("$repoRootPath/build")
include("relays.json")
into(extraAssetsDirectory)
}
tasks.register("ensureJniDirectoryExist") {
doFirst {
if (!file(extraJniDirectory).exists()) {
throw GradleException("Missing JNI directory: $extraJniDirectory")
}
}
}
// This is a safety net to avoid generating too big version codes, since that could potentially be
// hard and inconvenient to recover from.
tasks.register("ensureValidVersionCode") {
doLast {
val versionCode = project.android.defaultConfig.versionCode!!
if (versionCode >= MAX_ALLOWED_VERSION_CODE) {
throw GradleException("Bad version code: $versionCode")
}
}
}
tasks.create("printVersion") {
doLast {
println("versionCode=${project.android.defaultConfig.versionCode}")
println("versionName=${project.android.defaultConfig.versionName}")
}
}
afterEvaluate {
tasks.withType(com.android.build.gradle.internal.lint.AndroidLintAnalysisTask::class.java) {
mustRunAfter(tasks.getByName("copyExtraAssets"))
}
}
play { serviceAccountCredentials.set(file("play-api-key.json")) }
dependencies {
implementation(project(Dependencies.Mullvad.commonLib))
implementation(project(Dependencies.Mullvad.daemonGrpc))
implementation(project(Dependencies.Mullvad.endpointLib))
implementation(project(Dependencies.Mullvad.intentLib))
implementation(project(Dependencies.Mullvad.mapLib))
implementation(project(Dependencies.Mullvad.modelLib))
implementation(project(Dependencies.Mullvad.paymentLib))
implementation(project(Dependencies.Mullvad.resourceLib))
implementation(project(Dependencies.Mullvad.sharedLib))
implementation(project(Dependencies.Mullvad.talpidLib))
implementation(project(Dependencies.Mullvad.tileService))
implementation(project(Dependencies.Mullvad.themeLib))
implementation(project(Dependencies.Mullvad.vpnService))
// Play implementation
playImplementation(project(Dependencies.Mullvad.billingLib))
implementation(Dependencies.commonsValidator)
implementation(Dependencies.AndroidX.activityCompose)
implementation(Dependencies.AndroidX.coreKtx)
implementation(Dependencies.AndroidX.coreSplashscreen)
implementation(Dependencies.AndroidX.lifecycleRuntimeKtx)
implementation(Dependencies.AndroidX.lifecycleViewmodelKtx)
implementation(Dependencies.AndroidX.lifecycleRuntimeCompose)
implementation(Dependencies.Arrow.core)
implementation(Dependencies.Arrow.resilience)
implementation(Dependencies.Compose.constrainLayout)
implementation(Dependencies.Compose.foundation)
implementation(Dependencies.Compose.material3)
implementation(Dependencies.Compose.ui)
implementation(Dependencies.Compose.uiUtil)
implementation(Dependencies.Compose.destinations)
ksp(Dependencies.Compose.destinationsKsp)
implementation(Dependencies.jodaTime)
implementation(Dependencies.kermit)
implementation(Dependencies.Koin.core)
implementation(Dependencies.Koin.android)
implementation(Dependencies.Koin.compose)
implementation(Dependencies.Kotlin.reflect)
implementation(Dependencies.Kotlin.stdlib)
implementation(Dependencies.KotlinX.coroutinesAndroid)
// UI tooling
implementation(Dependencies.Compose.uiToolingPreview)
debugImplementation(Dependencies.Compose.uiTooling)
// Leak canary
leakCanaryImplementation(Dependencies.leakCanary)
// Needed for createComposeExtension() and createAndroidComposeExtension()
debugImplementation(Dependencies.Compose.uiTestManifest)
testImplementation(project(Dependencies.Mullvad.commonTestLib))
testImplementation(Dependencies.Kotlin.test)
testImplementation(Dependencies.KotlinX.coroutinesTest)
testImplementation(Dependencies.MockK.core)
testImplementation(Dependencies.turbine)
testImplementation(Dependencies.junitApi)
testRuntimeOnly(Dependencies.junitEngine)
testImplementation(Dependencies.junitParams)
// UI test dependencies
debugImplementation(Dependencies.Compose.testManifest)
androidTestImplementation(Dependencies.Koin.test)
androidTestImplementation(Dependencies.Kotlin.test)
androidTestImplementation(Dependencies.MockK.android)
androidTestImplementation(Dependencies.junitApi)
androidTestImplementation(Dependencies.Compose.junit5)
}