-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathbuild.gradle
More file actions
423 lines (364 loc) · 17.7 KB
/
build.gradle
File metadata and controls
423 lines (364 loc) · 17.7 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
plugins {
alias libs.plugins.android.application
alias libs.plugins.compose.compiler
alias libs.plugins.dependency.analysis
alias libs.plugins.kotlin.android
}
apply from: "$project.rootDir/automation/gradle/versionCode.gradle"
import com.android.build.api.variant.FilterConfiguration
import com.android.build.gradle.internal.tasks.AppPreBuildTask
import groovy.json.JsonOutput
android {
defaultConfig {
applicationId "org.mozilla.reference.browser"
buildToolsVersion Config.buildToolsVersion
compileSdk {
version = release(Config.compileSdkMajorVersion) {
minorApiLevel = Config.compileSdkMinorVersion
}
}
minSdkVersion Config.minSdkVersion
targetSdkVersion Config.targetSdkVersion
versionCode 1
versionName Config.generateDebugVersionName()
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
}
def releaseTemplate = {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
matchingFallbacks = ['release'] // Use on the "release" build type in dependencies (AARs)
if (gradle.hasProperty("localProperties.autosignReleaseWithDebugKey")) {
signingConfig signingConfigs.debug
}
if (gradle.hasProperty("localProperties.debuggable")) {
debuggable true
}
}
buildFeatures {
buildConfig = true
compose = true
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
raptor releaseTemplate >> { // the ">>" concatenates the raptor-specific options with the template
applicationIdSuffix ".raptor"
manifestPlaceholders.isRaptorEnabled = "true"
matchingFallbacks = ['release']
}
nightly releaseTemplate >> {
buildConfigField "boolean", "IS_RELEASED", "true"
}
}
variantFilter { // There's a "release" build type that exists by default that we don't use (it's replaced by "nightly" and "beta")
if (buildType.name == 'release') {
setIgnore true
}
}
testOptions {
execution = 'ANDROIDX_TEST_ORCHESTRATOR'
animationsDisabled = true
}
lintOptions {
lintConfig = file("lint.xml")
baseline file("lint-baseline.xml")
disable 'GradleDependency', 'AndroidGradlePluginVersion'
}
splits {
abi {
enable = true
reset()
include "armeabi-v7a", "arm64-v8a", "x86_64"
}
}
namespace = 'org.mozilla.reference.browser'
}
kotlin {
jvmToolchain(Config.jvmTargetCompatibility)
}
def baseVersionCode = generatedVersionCode
android.applicationVariants.configureEach { variant ->
// -------------------------------------------------------------------------------------------------
// Sentry: Read token from local file if it exists (Only release builds)
// -------------------------------------------------------------------------------------------------
print("Sentry token: "+ variant.name)
try {
def token = new File("${rootDir}/.sentry_token").text.trim()
buildConfigField 'String', 'SENTRY_TOKEN', '"' + token + '"'
println "(Added from .sentry_token file)"
} catch (FileNotFoundException ignored) {
buildConfigField 'String', 'SENTRY_TOKEN', 'null'
println(" :( ")
}
// -------------------------------------------------------------------------------------------------
// Activating crash reports with command line parameter.
// -------------------------------------------------------------------------------------------------
if (project.hasProperty("crashReportEnabled") && project.property("crashReportEnabled") == "true") {
buildConfigField 'boolean', 'CRASH_REPORTING_ENABLED', 'true'
} else {
buildConfigField 'boolean', 'CRASH_REPORTING_ENABLED', 'false'
}
// -------------------------------------------------------------------------------------------------
// Activating telemetry with command line paramter.
// -------------------------------------------------------------------------------------------------
if (project.hasProperty("telemetry") && project.property("telemetry") == "true") {
buildConfigField 'boolean', 'TELEMETRY_ENABLED', 'true'
} else {
buildConfigField 'boolean', 'TELEMETRY_ENABLED', 'false'
}
// -------------------------------------------------------------------------------------------------
// Generating version codes for Google Play
// -------------------------------------------------------------------------------------------------
if (variant.buildType.buildConfigFields['IS_RELEASED']?.value) {
// The Google Play Store does not allow multiple APKs for the same app that all have the
// same version code. Therefore we need to have different version codes for our ARM and x86
// builds. See https://developer.android.com/studio/publish/versioning
// Our x86 builds need a higher version code to avoid installing ARM builds on an x86 device
// with ARM compatibility mode.
// AAB builds need a version code that is distinct from any APK builds. Since AAB and APK
// builds may run in parallel, AAB and APK version codes might be based on the same
// (minute granularity) time of day. To avoid conflicts, we ensure the minute portion
// of the version code is even for APKs and odd for AABs.
def versionName = Config.releaseVersionName(project)
variant.outputs.each { output ->
def abi = output.getFilter(FilterConfiguration.FilterType.ABI.name())
def aab = project.hasProperty("aab")
// ensure baseVersionCode is an even number
if (baseVersionCode % 2) {
baseVersionCode = baseVersionCode + 1
}
def versionCodeOverride = baseVersionCode
if (aab) {
// AAB version code is odd
versionCodeOverride = baseVersionCode + 1
println("versionCode for AAB = $versionCodeOverride")
} else {
// APK version codes are even
if (abi == "x86_64") {
versionCodeOverride = baseVersionCode + 6
} else if (abi == "x86") {
versionCodeOverride = baseVersionCode + 4
} else if (abi == "arm64-v8a") {
versionCodeOverride = baseVersionCode + 2
} else if (abi == "armeabi-v7a") {
versionCodeOverride = baseVersionCode
}
println("versionCode for $abi = $versionCodeOverride")
}
output.versionNameOverride = versionName
output.versionCodeOverride = versionCodeOverride
}
// If this is a release build, validate that "versionName" is set
tasks.withType(AppPreBuildTask).configureEach { prebuildTask ->
// You can't add a closure to a variant, so we need to look for an early variant-specific type
// of task (AppPreBuildTask is the first) and filter to make sure we're looking at the task for
// this variant that we're currently configuring
if (prebuildTask.variantName != variant.name) {
return
}
// Append to the task so the first thing it does is run our validation
prebuildTask.doFirst {
if (!project.hasProperty('versionName')) {
throw new RuntimeException("Release builds require the 'versionName' property to be set.\n" +
"If you're using an IDE, set your build variant to be a \"debug\" type.\n" +
"If you're using the command-line, either build a debug variant instead ('./gradlew assembleDebug')\n" +
"\tor continue building the release build and set the \"versionName\" property ('./gradlew -PversionName=<...> assembleNightly').")
// TODO when Android Studio 3.5.0 is prevalent, we can set the "debug" build type as the default
// https://issuetracker.google.com/issues/36988145#comment59
}
}
}
}
// -------------------------------------------------------------------------------------------------
// BuildConfig: Set flag for official builds; similar to MOZILLA_OFFICIAL in mozilla-central.
// -------------------------------------------------------------------------------------------------
if (project.hasProperty("official") || gradle.hasProperty("localProperties.official")) {
buildConfigField 'Boolean', 'MOZILLA_OFFICIAL', 'true'
} else {
buildConfigField 'Boolean', 'MOZILLA_OFFICIAL', 'false'
}
}
// Select the Glean from GeckoView.
// `service-sync-logins` requires Glean, which pulls in glean-native,
// but that's also provided by geckoview-omni, so now we need to select which one to use.
project.configurations.configureEach {
resolutionStrategy.capabilitiesResolution.withCapability("org.mozilla.telemetry:glean-native") {
def toBeSelected = candidates.find { it.id instanceof ModuleComponentIdentifier && it.id.module.contains('geckoview') }
if (toBeSelected != null) {
select(toBeSelected)
}
because 'use GeckoView Glean instead of standalone Glean'
}
}
dependencies {
// We pick up JNA transitively by way of Glean, which is currently on version 5.14.0.
// However, we need to force version 5.17.0 due to Google Play's 16KB page size requirement.
// JNA 5.15.0+ crashes on Android <7, however, so it can't be bumped in Glean at this time.
// Therefore, manually force the use of version 5.17.0 at the app level since we only support
// running on Android 8+ now anyway.
constraints {
implementation(libs.jna)
}
implementation libs.androidx.activity
implementation libs.androidx.annotation
implementation libs.androidx.appcompat
implementation libs.androidx.browser
implementation libs.androidx.cardview
implementation libs.androidx.constraintlayout
implementation libs.androidx.coordinatorlayout
implementation libs.androidx.core.ktx
implementation libs.androidx.fragment
implementation libs.androidx.lifecycle.common
implementation libs.androidx.lifecycle.compose
implementation libs.androidx.lifecycle.process
implementation libs.androidx.lifecycle.viewmodel
implementation libs.androidx.preference.ktx
implementation libs.androidx.recyclerview
implementation libs.androidx.swiperefreshlayout
implementation libs.androidx.work.runtime.ktx
implementation platform(libs.androidx.compose.bom)
implementation libs.androidx.compose.foundation
implementation libs.androidx.compose.material3
implementation libs.androidx.compose.runtime
implementation libs.androidx.compose.ui.base
implementation libs.androidx.compose.ui.graphics
implementation libs.androidx.compose.ui.text
implementation libs.androidx.compose.ui.tooling
implementation libs.google.material
implementation libs.jspecify
implementation libs.kotlinx.coroutines.core
implementation libs.mozilla.browser.domains
implementation libs.mozilla.browser.engine.gecko
implementation libs.mozilla.browser.errorpages
implementation libs.mozilla.browser.icons
implementation libs.mozilla.browser.menu
implementation libs.mozilla.browser.menu2
implementation libs.mozilla.browser.session.storage
implementation libs.mozilla.browser.state
implementation libs.mozilla.browser.storage.sync
implementation libs.mozilla.browser.tabstray
implementation libs.mozilla.browser.thumbnails
implementation libs.mozilla.browser.toolbar
implementation libs.mozilla.compose.awesomebar
implementation libs.mozilla.concept.awesomebar
implementation libs.mozilla.concept.base
implementation libs.mozilla.concept.engine
implementation libs.mozilla.concept.fetch
implementation libs.mozilla.concept.menu
implementation libs.mozilla.concept.push
implementation libs.mozilla.concept.storage
implementation libs.mozilla.concept.sync
implementation libs.mozilla.concept.toolbar
implementation libs.mozilla.feature.accounts.base
implementation libs.mozilla.feature.accounts.push
implementation libs.mozilla.feature.addons
implementation libs.mozilla.feature.app.links
implementation libs.mozilla.feature.awesomebar
implementation libs.mozilla.feature.autofill
implementation libs.mozilla.feature.contextmenu
implementation libs.mozilla.feature.customtabs
implementation libs.mozilla.feature.downloads
implementation libs.mozilla.feature.findinpage
implementation libs.mozilla.feature.intent
implementation libs.mozilla.feature.media
implementation libs.mozilla.feature.prompts
implementation libs.mozilla.feature.push
implementation libs.mozilla.feature.pwa
implementation libs.mozilla.feature.qr
implementation libs.mozilla.feature.readerview
implementation libs.mozilla.feature.search
implementation libs.mozilla.feature.session
implementation libs.mozilla.feature.sitepermissions
implementation libs.mozilla.feature.syncedtabs
implementation libs.mozilla.feature.tabs
implementation libs.mozilla.feature.toolbar
implementation libs.mozilla.feature.webauthn
implementation libs.mozilla.feature.webcompat
implementation libs.mozilla.feature.webnotifications
implementation libs.mozilla.lib.crash.base
implementation libs.mozilla.lib.crash.sentry
implementation libs.mozilla.lib.dataprotect
implementation libs.mozilla.lib.publicsuffixlist
implementation libs.mozilla.lib.push.firebase
implementation libs.mozilla.lib.state
implementation libs.mozilla.service.firefox.accounts
implementation libs.mozilla.service.location
implementation libs.mozilla.service.sync.logins
implementation libs.mozilla.support.appservices
implementation libs.mozilla.support.base
implementation libs.mozilla.support.ktx
implementation libs.mozilla.support.utils
implementation libs.mozilla.support.webextensions
implementation libs.mozilla.ui.colors
implementation libs.mozilla.ui.icons
implementation libs.mozilla.ui.tabcounter
implementation libs.mozilla.ui.widgets
androidTestImplementation libs.androidx.test.espresso.core
androidTestImplementation libs.androidx.test.espresso.idling.resources
constraints {
implementation(libs.androidx.test.monitor)
}
androidTestImplementation libs.androidx.test.monitor
androidTestImplementation libs.androidx.test.rules
androidTestImplementation libs.androidx.test.runner
androidTestImplementation libs.androidx.test.uiautomator
androidTestImplementation libs.hamcrest.core
androidTestImplementation libs.hamcrest.library
androidTestImplementation libs.junit
androidTestImplementation libs.mockwebserver
androidTestImplementation libs.okhttp
constraints {
implementation(libs.okio) // needed to avoid picking up an older release transitively
}
androidTestImplementation libs.okio
androidTestUtil libs.androidx.test.orchestrator
}
// -------------------------------------------------------------------------------------------------
// Task for printing APK information for the requested variant
// Usage: ./gradlew printVariants
// -------------------------------------------------------------------------------------------------
tasks.register('printVariants') {
doLast {
def variants = android.applicationVariants.collect { variant ->
[
apks : variant.outputs.collect { output ->
[
abi : output.getFilter(FilterConfiguration.FilterType.ABI.name()),
fileName: output.outputFile.name
]
},
build_type: variant.buildType.name,
name : variant.name,
]
}
println 'variants: ' + JsonOutput.toJson(variants)
}
}
tasks.register('printGeckoviewVersion') {
doLast {
def configuration = configurations.implementationDependenciesMetadata
def dependencies = configuration.incoming.resolutionResult.allDependencies
def geckoviewDependency = dependencies.find { it.selected.id.moduleIdentifier.group == 'org.mozilla.geckoview' }
println('geckoviewVersion: ' + JsonOutput.toJson(geckoviewDependency.selected.moduleVersion.version))
}
}
if (gradle.hasProperty('localProperties.dependencySubstitutions.geckoviewTopsrcdir')) {
if (gradle.hasProperty('localProperties.dependencySubstitutions.geckoviewTopobjdir')) {
ext.topobjdir = gradle."localProperties.dependencySubstitutions.geckoviewTopobjdir"
}
ext.topsrcdir = gradle."localProperties.dependencySubstitutions.geckoviewTopsrcdir"
apply from: "${topsrcdir}/substitute-local-geckoview.gradle"
}
if (gradle.hasProperty('localProperties.autoPublish.android-components.dir')) {
ext.acSrcDir = gradle."localProperties.autoPublish.android-components.dir"
apply from: "${acSrcDir}/substitute-local-ac.gradle"
}
if (gradle.hasProperty('localProperties.autoPublish.application-services.dir')) {
ext.appServicesSrcDir = gradle."localProperties.autoPublish.application-services.dir"
apply from: "../${appServicesSrcDir}/build-scripts/substitute-local-appservices.gradle"
}