Source code

Revision control

Other Tools

1
buildDir "${topobjdir}/gradle/build/mobile/android/geckoview"
2
3
import groovy.json.JsonOutput
4
5
apply plugin: 'com.android.library'
6
apply plugin: 'checkstyle'
7
apply plugin: 'kotlin-android'
8
9
apply from: "${topsrcdir}/mobile/android/gradle/product_flavors.gradle"
10
11
// The SDK binding generation tasks depend on the JAR creation task of the
12
// :annotations project.
13
evaluationDependsOn(':annotations')
14
15
// Non-official versions are like "61.0a1", where "a1" is the milestone.
16
// This simply strips that off, leaving "61.0" in this example.
17
def getAppVersionWithoutMilestone() {
18
return mozconfig.substs.MOZ_APP_VERSION.replaceFirst(/a[0-9]/, "")
19
}
20
21
// This converts MOZ_APP_VERSION into an integer
22
// version code.
23
//
24
// We take something like 58.1.2a1 and come out with 5800102
25
// This gives us 3 digits for the major number, and 2 digits
26
// each for the minor and build number. Beta and Release
27
//
28
// This must be synchronized with _compute_gecko_version(...) in /taskcluster/taskgraph/transforms/task.py
29
def computeVersionCode() {
30
String appVersion = getAppVersionWithoutMilestone()
31
32
// Split on the dot delimiter, e.g. 58.1.1a1 -> ["58, "1", "1a1"]
33
String[] parts = appVersion.split('\\.')
34
35
assert parts.size() == 2 || parts.size() == 3
36
37
// Major
38
int code = Integer.parseInt(parts[0]) * 100000
39
40
// Minor
41
code += Integer.parseInt(parts[1]) * 100
42
43
// Build
44
if (parts.size() == 3) {
45
code += Integer.parseInt(parts[2])
46
}
47
48
return code;
49
}
50
51
def computeVersionNumber() {
52
def appVersion = getAppVersionWithoutMilestone()
53
def parts = appVersion.split('\\.')
54
return parts[0] + "." + parts[1] + "." + getBuildId()
55
}
56
57
// Mimic Python: open(os.path.join(buildconfig.topobjdir, 'buildid.h')).readline().split()[2]
58
def getBuildId() {
59
return file("${topobjdir}/buildid.h").getText('utf-8').split()[2]
60
}
61
62
android {
63
compileSdkVersion project.ext.compileSdkVersion
64
65
useLibrary 'android.test.runner'
66
useLibrary 'android.test.base'
67
useLibrary 'android.test.mock'
68
69
defaultConfig {
70
targetSdkVersion project.ext.targetSdkVersion
71
minSdkVersion project.ext.minSdkVersion
72
manifestPlaceholders = project.ext.manifestPlaceholders
73
74
versionCode computeVersionCode()
75
versionName "${mozconfig.substs.MOZ_APP_VERSION}-${mozconfig.substs.MOZ_UPDATE_CHANNEL}"
76
consumerProguardFiles 'proguard-rules.txt'
77
78
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
79
80
buildConfigField 'String', "GRE_MILESTONE", "\"${mozconfig.substs.GRE_MILESTONE}\""
81
buildConfigField 'String', "MOZ_APP_BASENAME", "\"${mozconfig.substs.MOZ_APP_BASENAME}\"";
82
83
// For the benefit of future archaeologists:
84
// GRE_BUILDID is exactly the same as MOZ_APP_BUILDID unless you're running
85
// on XULRunner, which is never the case on Android.
86
buildConfigField 'String', "MOZ_APP_BUILDID", "\"${getBuildId()}\"";
87
buildConfigField 'String', "MOZ_APP_ID", "\"${mozconfig.substs.MOZ_APP_ID}\"";
88
buildConfigField 'String', "MOZ_APP_NAME", "\"${mozconfig.substs.MOZ_APP_NAME}\"";
89
buildConfigField 'String', "MOZ_APP_VENDOR", "\"${mozconfig.substs.MOZ_APP_VENDOR}\"";
90
buildConfigField 'String', "MOZ_APP_VERSION", "\"${mozconfig.substs.MOZ_APP_VERSION}\"";
91
buildConfigField 'String', "MOZ_APP_DISPLAYNAME", "\"${mozconfig.substs.MOZ_APP_DISPLAYNAME}\"";
92
buildConfigField 'String', "MOZ_APP_UA_NAME", "\"${mozconfig.substs.MOZ_APP_UA_NAME}\"";
93
buildConfigField 'String', "MOZ_UPDATE_CHANNEL", "\"${mozconfig.substs.MOZ_UPDATE_CHANNEL}\"";
94
95
// MOZILLA_VERSION is oddly quoted from autoconf, but we don't have to handle it specially in Gradle.
96
buildConfigField 'String', "MOZILLA_VERSION", "\"${mozconfig.substs.MOZILLA_VERSION}\"";
97
buildConfigField 'String', "OMNIJAR_NAME", "\"${mozconfig.substs.OMNIJAR_NAME}\"";
98
99
// Keep in sync with actual user agent in nsHttpHandler::BuildUserAgent
100
buildConfigField 'String', "USER_AGENT_GECKOVIEW_MOBILE", "\"Mozilla/5.0 (Android \" + android.os.Build.VERSION.RELEASE + \"; Mobile; rv:\" + ${mozconfig.defines.MOZILLA_UAVERSION} + \") Gecko/\" + ${mozconfig.defines.MOZILLA_UAVERSION} + \" Firefox/\" + ${mozconfig.defines.MOZILLA_UAVERSION}";
101
buildConfigField 'String', "USER_AGENT_GECKOVIEW_TABLET", "\"Mozilla/5.0 (Android \" + android.os.Build.VERSION.RELEASE + \"; Tablet; rv:\" + ${mozconfig.defines.MOZILLA_UAVERSION} + \") Gecko/\" + ${mozconfig.defines.MOZILLA_UAVERSION} + \" Firefox/\" + ${mozconfig.defines.MOZILLA_UAVERSION}";
102
103
buildConfigField 'int', 'MIN_SDK_VERSION', mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION;
104
105
// Is the underlying compiled C/C++ code compiled with --enable-debug?
106
buildConfigField 'boolean', 'DEBUG_BUILD', mozconfig.substs.MOZ_DEBUG ? 'true' : 'false';
107
108
// See this wiki page for more details about channel specific build defines:
110
// This makes no sense for GeckoView and should be removed as soon as possible.
111
buildConfigField 'boolean', 'RELEASE_OR_BETA', mozconfig.substs.RELEASE_OR_BETA ? 'true' : 'false';
112
// This makes no sense for GeckoView and should be removed as soon as possible.
113
buildConfigField 'boolean', 'NIGHTLY_BUILD', mozconfig.substs.NIGHTLY_BUILD ? 'true' : 'false';
114
// This makes no sense for GeckoView and should be removed as soon as possible.
115
buildConfigField 'boolean', 'MOZ_CRASHREPORTER', mozconfig.substs.MOZ_CRASHREPORTER ? 'true' : 'false';
116
117
// Official corresponds, roughly, to whether this build is performed on
118
// Mozilla's continuous integration infrastructure. You should disable
119
// developer-only functionality when this flag is set.
120
// This makes no sense for GeckoView and should be removed as soon as possible.
121
buildConfigField 'boolean', 'MOZILLA_OFFICIAL', mozconfig.substs.MOZILLA_OFFICIAL ? 'true' : 'false';
122
}
123
124
project.configureProductFlavors.delegate = it
125
project.configureProductFlavors()
126
127
compileOptions {
128
sourceCompatibility JavaVersion.VERSION_1_8
129
targetCompatibility JavaVersion.VERSION_1_8
130
}
131
132
dexOptions {
133
javaMaxHeapSize "6g"
134
}
135
136
lintOptions {
137
abortOnError false
138
}
139
140
sourceSets {
141
main {
142
java {
143
srcDir "${topsrcdir}/mobile/android/geckoview/src/thirdparty/java"
144
145
if (!mozconfig.substs.MOZ_ANDROID_HLS_SUPPORT) {
146
exclude 'com/google/android/exoplayer2/**'
147
exclude 'org/mozilla/gecko/media/GeckoHlsAudioRenderer.java'
148
exclude 'org/mozilla/gecko/media/GeckoHlsPlayer.java'
149
exclude 'org/mozilla/gecko/media/GeckoHlsRendererBase.java'
150
exclude 'org/mozilla/gecko/media/GeckoHlsVideoRenderer.java'
151
exclude 'org/mozilla/gecko/media/Utils.java'
152
}
153
154
if (mozconfig.substs.MOZ_WEBRTC) {
155
srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/base/java/src"
156
srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src"
157
}
158
}
159
160
resources {
161
if (mozconfig.substs.MOZ_ASAN) {
162
// If this is an ASAN build, include a `wrap.sh` for Android 8.1+ devices. See
164
srcDir "${topsrcdir}/mobile/android/geckoview/src/asan/resources"
165
}
166
}
167
168
assets {
169
}
170
}
171
}
172
}
173
174
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
175
// Translate Kotlin messages like "w: ..." and "e: ..." into
176
// "...: warning: ..." and "...: error: ...", to make Treeherder understand.
177
def listener = {
178
if (it.startsWith("e: warnings found")) {
179
return
180
}
181
182
if (it.startsWith('w: ') || it.startsWith('e: ')) {
183
def matches = (it =~ /([ew]): (.+): \((\d+), (\d+)\): (.*)/)
184
if (!matches) {
185
logger.quiet "kotlinc message format has changed!"
186
if (it.startsWith('w: ')) {
187
// For warnings, don't continue because we don't want to throw an
188
// exception. For errors, we want the exception so that the new error
189
// message format gets translated properly.
190
return
191
}
192
}
193
def (_, type, file, line, column, message) = matches[0]
194
type = (type == 'w') ? 'warning' : 'error'
195
// Use logger.lifecycle, which does not go through stderr again.
196
logger.lifecycle "$file:$line:$column: $type: $message"
197
}
198
} as StandardOutputListener
199
200
kotlinOptions {
201
allWarningsAsErrors = true
202
}
203
204
doFirst {
205
logging.addStandardErrorListener(listener)
206
}
207
doLast {
208
logging.removeStandardErrorListener(listener)
209
}
210
}
211
212
dependencies {
213
implementation "com.android.support:support-v4:$support_library_version"
214
implementation "com.android.support:palette-v7:$support_library_version"
215
implementation "org.yaml:snakeyaml:1.24:android"
216
217
implementation "android.arch.lifecycle:extensions:$lifecycle_library_version"
218
implementation "android.arch.lifecycle:common-java8:$lifecycle_library_version"
219
220
testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
221
testImplementation 'junit:junit:4.12'
222
testImplementation 'org.robolectric:robolectric:4.3'
223
testImplementation 'org.mockito:mockito-core:1.10.19'
224
225
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
226
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2"
227
androidTestImplementation 'androidx.test:runner:1.1.0'
228
androidTestImplementation 'androidx.test:rules:1.1.0'
229
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
230
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
231
232
androidTestImplementation "com.android.support:support-annotations:$support_library_version"
233
234
androidTestImplementation 'com.koushikdutta.async:androidasync:2.+'
235
}
236
237
apply from: "${topsrcdir}/mobile/android/gradle/with_gecko_binaries.gradle"
238
239
android.libraryVariants.all { variant ->
240
// See the notes in mobile/android/app/build.gradle for details on including
241
// Gecko binaries and the Omnijar.
242
if ((variant.productFlavors*.name).contains('withGeckoBinaries')) {
243
configureVariantWithGeckoBinaries(variant)
244
}
245
246
// Javadoc and Sources JAR configuration cribbed from
248
// informed by
250
// and amended from numerous Stackoverflow posts.
251
def name = variant.name
252
def javadoc = task "javadoc${name.capitalize()}"(type: Javadoc) {
253
description = "Generate Javadoc for build variant $name"
254
destinationDir = new File(destinationDir, variant.baseName)
255
doFirst {
256
classpath = files(variant.javaCompileProvider.get().classpath.files)
257
}
258
259
def results = []
260
def listener = {
261
// Like '/abs/path/to/topsrcdir/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/ContentBlocking.java:480: warning: no @return'
262
def matches = (it =~ /(.+):(\d+): (warning|error): (.*)/)
263
if (!matches) {
264
return
265
}
266
def (_, file, line, level, message) = matches[0]
267
results << [path: file, lineno: line, level: level, message: message]
268
} as StandardOutputListener
269
270
doFirst {
271
logging.addStandardErrorListener(listener)
272
}
273
274
doLast {
275
logging.removeStandardErrorListener(listener)
276
277
// We used to treat Javadoc warnings as errors here; now we rely on the
278
// `android-javadoc` linter to fail in the face of Javadoc warnings.
279
def resultsJson = JsonOutput.toJson(results)
280
281
file("$buildDir/reports").mkdirs()
282
file("$buildDir/reports/javadoc-results-${name}.json").write(resultsJson)
283
}
284
285
source = variant.sourceSets.collect({ it.java.srcDirs })
286
exclude '**/R.java', '**/BuildConfig.java'
287
include 'org/mozilla/geckoview/**.java'
288
options.addPathOption('sourcepath', ':').setValue(
289
variant.sourceSets.collect({ it.java.srcDirs }).flatten() +
290
variant.generateBuildConfigProvider.get().sourceOutputDir +
291
variant.aidlCompileProvider.get().sourceOutputDir)
292
293
// javadoc 8 has a bug that requires the rt.jar file from the JRE to be
294
// in the bootclasspath (https://stackoverflow.com/a/30458820).
295
options.bootClasspath = [
296
file("${System.properties['java.home']}/lib/rt.jar")] + android.bootClasspath
297
options.memberLevel = JavadocMemberLevel.PROTECTED
298
options.source = 8
299
// Bug 1555255: don't require a network connection to produce Javadoc.
301
options.linksOffline("https://d.android.com/reference/", "${android.sdkDirectory}/docs/reference");
302
303
options.docTitle = "GeckoView ${mozconfig.substs.MOZ_APP_VERSION} API"
304
options.header = "GeckoView ${mozconfig.substs.MOZ_APP_VERSION} API"
305
options.noTimestamp = true
306
options.noIndex = true
307
options.noQualifiers = ['java.lang']
308
options.tags = ['hide:a:']
309
}
310
311
def javadocJar = task("javadocJar${name.capitalize()}", type: Jar, dependsOn: javadoc) {
312
classifier = 'javadoc'
313
from javadoc.destinationDir
314
}
315
316
// This task is used by `mach android geckoview-docs`.
317
task("javadocCopyJar${name.capitalize()}", type: Copy) {
318
from(javadocJar.destinationDir) {
319
include 'geckoview-*-javadoc.jar'
320
rename { _ -> 'geckoview-javadoc.jar' }
321
}
322
into javadocJar.destinationDir
323
dependsOn javadocJar
324
}
325
326
def sourcesJar = task("sourcesJar${name.capitalize()}", type: Jar) {
327
classifier 'sources'
328
description = "Generate Javadoc for build variant $name"
329
destinationDir = new File(destinationDir, variant.baseName)
330
from files(variant.javaCompileProvider.get().source)
331
}
332
333
task("checkstyle${name.capitalize()}", type: Checkstyle) {
334
classpath = variant.javaCompileProvider.get().classpath
335
configFile file("checkstyle.xml")
336
// TODO: cleanup and include all sources
337
source = ['src/main/java/']
338
include '**/*.java'
339
}
340
}
341
342
android.libraryVariants.all { variant ->
343
if (variant.name == mozconfig.substs.GRADLE_ANDROID_GECKOVIEW_VARIANT_NAME) {
344
configureLibraryVariantWithJNIWrappers(variant, "Generated")
345
}
346
}
347
348
android.libraryVariants.all { variant ->
349
// At this point, the Android-Gradle plugin has created all the Android
350
// tasks and configurations. This is the time for us to declare additional
351
// Glean files to package into AAR files. This packs `metrics.yaml` in the
352
// root of the AAR, sibling to `AndroidManifest.xml` and `classes.jar`. By
353
// default, consumers of the AAR will ignore this file, but consumers that
354
// look for it can find it (provided GeckoView is a `module()` dependency
355
// and not a `project()` dependency.) Under the hood this uses that the
356
// task provided by `packageLibraryProvider` task is a Maven `Zip` task,
357
// and we can simply extend its inputs. See
359
variant.packageLibraryProvider.get().from("${topsrcdir}/toolkit/components/telemetry/geckoview/streaming/metrics.yaml")
360
}
361
362
apply plugin: 'maven-publish'
363
364
version = computeVersionNumber()
365
if (!mozconfig.substs.MOZILLA_OFFICIAL && !mozconfig.substs.MOZ_ANDROID_FAT_AAR_ARCHITECTURES) {
366
// Use -SNAPSHOT versions locally to enable the local GeckoView substitution flow.
367
version = "${version}-SNAPSHOT"
368
}
369
370
publishing {
371
publications {
372
android.libraryVariants.all { variant ->
373
"${variant.name}"(MavenPublication) {
374
pom {
375
groupId = 'org.mozilla.geckoview'
376
377
if (mozconfig.substs.MOZ_UPDATE_CHANNEL == 'release') {
378
// Release artifacts don't specify the channel, for the sake of simplicity.
379
artifactId = 'geckoview'
380
} else {
381
artifactId = "geckoview-${mozconfig.substs.MOZ_UPDATE_CHANNEL}"
382
}
383
384
if (mozconfig.substs.MOZILLA_OFFICIAL && !mozconfig.substs.MOZ_ANDROID_FAT_AAR_ARCHITECTURES) {
385
// In automation, per-architecture artifacts identify
386
// the architecture; multi-architecture artifacts don't.
387
// When building locally, we produce a "skinny AAR" with
388
// one target architecture masquerading as a "fat AAR"
389
// to enable Gradle composite builds to substitute this
390
// project into consumers easily.
391
artifactId = "${artifactId}-${mozconfig.substs.ANDROID_CPU_ARCH}"
392
}
393
395
396
licenses {
397
license {
398
name = 'The Mozilla Public License, v. 2.0'
400
distribution = 'repo'
401
}
402
}
403
404
scm {
405
if (mozconfig.substs.MOZ_INCLUDE_SOURCE_INFO) {
407
connection = "scm::hg::${mozconfig.substs.MOZ_SOURCE_REPO}"
408
url = mozconfig.substs.MOZ_SOURCE_URL
409
tag = mozconfig.substs.MOZ_SOURCE_CHANGESET
410
} else {
411
// Default to mozilla-central.
412
connection = 'scm::hg::https://hg.mozilla.org/mozilla-central/'
414
}
415
}
416
417
// Unfortunately Gradle does not provide a way to expose dependencies for custom
418
// project types like Android plugins. So we need to add them manually to the POM
419
// XML here, or use a plugin that achieves the same (like
421
// manually since our dependencies are simple and plugins increase our complexity
422
// surface. This workaround can be removed after this issue is fixed:
424
withXml {
425
def dependenciesNode = asNode().appendNode('dependencies')
426
427
configurations.getByName("implementation").dependencies.each {
428
def dependencyNode = dependenciesNode.appendNode('dependency')
429
dependencyNode.appendNode('groupId', it.group)
430
dependencyNode.appendNode('artifactId', it.name)
431
dependencyNode.appendNode('version', it.version)
432
}
433
}
434
}
435
436
artifact tasks["bundle${variant.name.capitalize()}Aar"]
437
438
// Javadoc and sources for developer ergononomics.
439
artifact tasks["javadocJar${variant.name.capitalize()}"]
440
artifact tasks["sourcesJar${variant.name.capitalize()}"]
441
}
442
}
443
}
444
repositories {
445
maven {
446
url = "${project.buildDir}/maven"
447
}
448
}
449
}
450
451
// This is all related to the withGeckoBinaries approach; see
452
// mobile/android/gradle/with_gecko_binaries.gradle.
453
afterEvaluate {
454
// The bundle tasks are only present when the particular configuration is
455
// being built, so this task might not exist. (This is due to the way the
456
// Android Gradle plugin defines things during configuration.)
457
def bundleWithGeckoBinaries = tasks.findByName('bundleWithGeckoBinariesReleaseAar')
458
if (!bundleWithGeckoBinaries) {
459
return
460
}
461
462
// Remove default configuration, which is the release configuration, when
463
// we're actually building withGeckoBinaries. This makes `gradle install`
464
// install the withGeckoBinaries artifacts, not the release artifacts (which
465
// are withoutGeckoBinaries and not suitable for distribution.)
466
def Configuration archivesConfig = project.getConfigurations().getByName('archives')
467
archivesConfig.artifacts.removeAll { it.extension.equals('aar') }
468
469
// For now, ensure Kotlin is only used in tests.
470
android.sourceSets.all { sourceSet ->
471
if (sourceSet.name.startsWith('test') || sourceSet.name.startsWith('androidTest')) {
472
return
473
}
474
(sourceSet.java.srcDirs + sourceSet.kotlin.srcDirs).each {
475
if (!fileTree(it, { include '**/*.kt' }).empty) {
476
throw new GradleException("Kotlin used in non-test directory ${it.path}")
477
}
478
}
479
}
480
}
481
482
// Bug 1353055 - Strip 'vars' debugging information to agree with moz.build.
483
apply from: "${topsrcdir}/mobile/android/gradle/debug_level.gradle"
484
android.libraryVariants.all configureVariantDebugLevel
485
486
// There's nothing specific to the :geckoview project here -- this just needs to
487
// be somewhere where the Android plugin is available so that we can fish the
488
// path to "android.jar".
489
task("generateSDKBindings", type: JavaExec) {
490
classpath project(':annotations').jar.archivePath
491
classpath project(':annotations').compileJava.classpath
492
493
// To use the lint APIs: "Lint must be invoked with the System property
494
// com.android.tools.lint.bindir pointing to the ANDROID_SDK tools
495
// directory"
496
systemProperties = [
497
'com.android.tools.lint.bindir': "${android.sdkDirectory}/tools",
498
]
499
500
main = 'org.mozilla.gecko.annotationProcessors.SDKProcessor'
501
// We only want to generate bindings for the main framework JAR,
502
// but not any of the additional android.test libraries.
503
args android.bootClasspath.findAll { it.getName().startsWith('android.jar') }
504
args 16
505
args "${topobjdir}/widget/android/bindings"
506
507
// Configure the arguments at evaluation-time, not at configuration-time.
508
doFirst {
509
// From -Pgenerate_sdk_bindings_args=... on command line; missing in
510
// `android-gradle-dependencies` toolchain task.
511
if (project.hasProperty('generate_sdk_bindings_args')) {
512
args project.generate_sdk_bindings_args.split(';')
513
}
514
}
515
516
workingDir "${topsrcdir}/widget/android/bindings"
517
518
dependsOn project(':annotations').jar
519
}
520
521
apply plugin: 'org.mozilla.apilint'
522
523
apiLint {
524
// TODO: Change this to `org` after hiding org.mozilla.gecko
525
packageFilter = 'org.mozilla.geckoview'
526
changelogFileName = 'src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md'
527
skipClassesRegex = ['^org.mozilla.geckoview.BuildConfig$']
528
lintFilters = ['GV']
529
allowedPackages = [
530
'java',
531
'android',
532
'org.json',
533
'org.mozilla.geckoview',
534
]
535
}