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 "android.support.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
assets {
161
}
162
}
163
}
164
}
165
166
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
167
// Translate Kotlin messages like "w: ..." and "e: ..." into
168
// "...: warning: ..." and "...: error: ...", to make Treeherder understand.
169
def listener = {
170
if (it.startsWith("e: warnings found")) {
171
return
172
}
173
174
if (it.startsWith('w: ') || it.startsWith('e: ')) {
175
def matches = (it =~ /([ew]): (.+): \((\d+), (\d+)\): (.*)/)
176
if (!matches) {
177
logger.quiet "kotlinc message format has changed!"
178
if (it.startsWith('w: ')) {
179
// For warnings, don't continue because we don't want to throw an
180
// exception. For errors, we want the exception so that the new error
181
// message format gets translated properly.
182
return
183
}
184
}
185
def (_, type, file, line, column, message) = matches[0]
186
type = (type == 'w') ? 'warning' : 'error'
187
// Use logger.lifecycle, which does not go through stderr again.
188
logger.lifecycle "$file:$line:$column: $type: $message"
189
}
190
} as StandardOutputListener
191
192
kotlinOptions {
193
allWarningsAsErrors = true
194
}
195
196
doFirst {
197
logging.addStandardErrorListener(listener)
198
}
199
doLast {
200
logging.removeStandardErrorListener(listener)
201
}
202
}
203
204
dependencies {
205
implementation "com.android.support:support-v4:$support_library_version"
206
implementation "com.android.support:palette-v7:$support_library_version"
207
implementation "org.yaml:snakeyaml:1.24:android"
208
209
implementation "android.arch.lifecycle:extensions:$lifecycle_library_version"
210
implementation "android.arch.lifecycle:common-java8:$lifecycle_library_version"
211
212
testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
213
testImplementation 'junit:junit:4.12'
214
testImplementation 'org.robolectric:robolectric:4.3'
215
testImplementation 'org.mockito:mockito-core:1.10.19'
216
217
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
218
androidTestImplementation 'com.android.support.test:runner:1.0.2'
219
androidTestImplementation 'com.android.support.test:rules:1.0.2'
220
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
221
androidTestImplementation "com.android.support:support-annotations:$support_library_version"
222
223
androidTestImplementation 'org.eclipse.jetty:jetty-server:7.6.21.v20160908'
224
}
225
226
apply from: "${topsrcdir}/mobile/android/gradle/with_gecko_binaries.gradle"
227
228
android.libraryVariants.all { variant ->
229
// See the notes in mobile/android/app/build.gradle for details on including
230
// Gecko binaries and the Omnijar.
231
if ((variant.productFlavors*.name).contains('withGeckoBinaries')) {
232
configureVariantWithGeckoBinaries(variant)
233
}
234
235
// Javadoc and Sources JAR configuration cribbed from
237
// informed by
239
// and amended from numerous Stackoverflow posts.
240
def name = variant.name
241
def javadoc = task "javadoc${name.capitalize()}"(type: Javadoc) {
242
description = "Generate Javadoc for build variant $name"
243
destinationDir = new File(destinationDir, variant.baseName)
244
doFirst {
245
classpath = files(variant.javaCompileProvider.get().classpath.files)
246
}
247
248
def results = []
249
def listener = {
250
// Like '/abs/path/to/topsrcdir/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/ContentBlocking.java:480: warning: no @return'
251
def matches = (it =~ /(.+):(\d+): (warning|error): (.*)/)
252
if (!matches) {
253
return
254
}
255
def (_, file, line, level, message) = matches[0]
256
results << [path: file, lineno: line, level: level, message: message]
257
} as StandardOutputListener
258
259
doFirst {
260
logging.addStandardErrorListener(listener)
261
}
262
263
doLast {
264
logging.removeStandardErrorListener(listener)
265
266
// We used to treat Javadoc warnings as errors here; now we rely on the
267
// `android-javadoc` linter to fail in the face of Javadoc warnings.
268
def resultsJson = JsonOutput.toJson(results)
269
270
file("$buildDir/reports").mkdirs()
271
file("$buildDir/reports/javadoc-results-${name}.json").write(resultsJson)
272
}
273
274
source = variant.sourceSets.collect({ it.java.srcDirs })
275
exclude '**/R.java', '**/BuildConfig.java'
276
include 'org/mozilla/geckoview/**.java'
277
options.addPathOption('sourcepath', ':').setValue(
278
variant.sourceSets.collect({ it.java.srcDirs }).flatten() +
279
variant.generateBuildConfigProvider.get().sourceOutputDir +
280
variant.aidlCompileProvider.get().sourceOutputDir)
281
282
// javadoc 8 has a bug that requires the rt.jar file from the JRE to be
283
// in the bootclasspath (https://stackoverflow.com/a/30458820).
284
options.bootClasspath = [
285
file("${System.properties['java.home']}/lib/rt.jar")] + android.bootClasspath
286
options.memberLevel = JavadocMemberLevel.PROTECTED
287
options.source = 8
288
// Bug 1555255: don't require a network connection to produce Javadoc.
290
options.linksOffline("https://d.android.com/reference/", "${android.sdkDirectory}/docs/reference");
291
292
options.docTitle = "GeckoView ${mozconfig.substs.MOZ_APP_VERSION} API"
293
options.header = "GeckoView ${mozconfig.substs.MOZ_APP_VERSION} API"
294
options.noTimestamp = true
295
options.noIndex = true
296
options.noQualifiers = ['java.lang']
297
options.tags = ['hide:a:']
298
}
299
300
def javadocJar = task("javadocJar${name.capitalize()}", type: Jar, dependsOn: javadoc) {
301
classifier = 'javadoc'
302
from javadoc.destinationDir
303
}
304
305
// This task is used by `mach android geckoview-docs`.
306
task("javadocCopyJar${name.capitalize()}", type: Copy) {
307
from(javadocJar.destinationDir) {
308
include 'geckoview-*-javadoc.jar'
309
rename { _ -> 'geckoview-javadoc.jar' }
310
}
311
into javadocJar.destinationDir
312
dependsOn javadocJar
313
}
314
315
def sourcesJar = task("sourcesJar${name.capitalize()}", type: Jar) {
316
classifier 'sources'
317
description = "Generate Javadoc for build variant $name"
318
destinationDir = new File(destinationDir, variant.baseName)
319
from files(variant.javaCompileProvider.get().source)
320
}
321
322
task("checkstyle${name.capitalize()}", type: Checkstyle) {
323
classpath = variant.javaCompileProvider.get().classpath
324
configFile file("checkstyle.xml")
325
// TODO: cleanup and include all sources
326
source = ['src/main/java/']
327
include '**/*.java'
328
}
329
}
330
331
android.libraryVariants.all { variant ->
332
if (variant.name == mozconfig.substs.GRADLE_ANDROID_GECKOVIEW_VARIANT_NAME) {
333
configureLibraryVariantWithJNIWrappers(variant, "Generated")
334
}
335
}
336
337
android.libraryVariants.all { variant ->
338
// At this point, the Android-Gradle plugin has created all the Android
339
// tasks and configurations. This is the time for us to declare additional
340
// Glean files to package into AAR files. This packs `metrics.yaml` in the
341
// root of the AAR, sibling to `AndroidManifest.xml` and `classes.jar`. By
342
// default, consumers of the AAR will ignore this file, but consumers that
343
// look for it can find it (provided GeckoView is a `module()` dependency
344
// and not a `project()` dependency.) Under the hood this uses that the
345
// task provided by `packageLibraryProvider` task is a Maven `Zip` task,
346
// and we can simply extend its inputs. See
348
variant.packageLibraryProvider.get().from("${topsrcdir}/toolkit/components/telemetry/geckoview/streaming/metrics.yaml")
349
}
350
351
apply plugin: 'maven-publish'
352
353
version = computeVersionNumber()
354
355
publishing {
356
publications {
357
android.libraryVariants.all { variant ->
358
"${variant.name}"(MavenPublication) {
359
pom {
360
groupId = 'org.mozilla.geckoview'
361
362
if (mozconfig.substs.MOZ_UPDATE_CHANNEL == 'release') {
363
// Release artifacts don't specify the channel, for the sake of simplicity.
364
artifactId = 'geckoview'
365
} else {
366
artifactId = "geckoview-${mozconfig.substs.MOZ_UPDATE_CHANNEL}"
367
}
368
369
if (mozconfig.substs.MOZILLA_OFFICIAL && !mozconfig.substs.MOZ_ANDROID_FAT_AAR_ARCHITECTURES) {
370
// In automation, per-architecture artifacts identify
371
// the architecture; multi-architecture artifacts don't.
372
// When building locally, we produce a "skinny AAR" with
373
// one target architecture masquerading as a "fat AAR"
374
// to enable Gradle composite builds to substitute this
375
// project into consumers easily.
376
artifactId = "${artifactId}-${mozconfig.substs.ANDROID_CPU_ARCH}"
377
}
378
380
381
licenses {
382
license {
383
name = 'The Mozilla Public License, v. 2.0'
385
distribution = 'repo'
386
}
387
}
388
389
scm {
390
if (mozconfig.substs.MOZ_INCLUDE_SOURCE_INFO) {
392
connection = "scm::hg::${mozconfig.substs.MOZ_SOURCE_REPO}"
393
url = mozconfig.substs.MOZ_SOURCE_URL
394
tag = mozconfig.substs.MOZ_SOURCE_CHANGESET
395
} else {
396
// Default to mozilla-central.
397
connection = 'scm::hg::https://hg.mozilla.org/mozilla-central/'
399
}
400
}
401
402
// Unfortunately Gradle does not provide a way to expose dependencies for custom
403
// project types like Android plugins. So we need to add them manually to the POM
404
// XML here, or use a plugin that achieves the same (like
406
// manually since our dependencies are simple and plugins increase our complexity
407
// surface. This workaround can be removed after this issue is fixed:
409
withXml {
410
def dependenciesNode = asNode().appendNode('dependencies')
411
412
configurations.getByName("implementation").dependencies.each {
413
def dependencyNode = dependenciesNode.appendNode('dependency')
414
dependencyNode.appendNode('groupId', it.group)
415
dependencyNode.appendNode('artifactId', it.name)
416
dependencyNode.appendNode('version', it.version)
417
}
418
}
419
}
420
421
artifact tasks["bundle${variant.name.capitalize()}Aar"]
422
423
// Javadoc and sources for developer ergononomics.
424
artifact tasks["javadocJar${variant.name.capitalize()}"]
425
artifact tasks["sourcesJar${variant.name.capitalize()}"]
426
}
427
}
428
}
429
repositories {
430
maven {
431
url = "${project.buildDir}/maven"
432
}
433
}
434
}
435
436
// This is all related to the withGeckoBinaries approach; see
437
// mobile/android/gradle/with_gecko_binaries.gradle.
438
afterEvaluate {
439
// The bundle tasks are only present when the particular configuration is
440
// being built, so this task might not exist. (This is due to the way the
441
// Android Gradle plugin defines things during configuration.)
442
def bundleWithGeckoBinaries = tasks.findByName('bundleWithGeckoBinariesReleaseAar')
443
if (!bundleWithGeckoBinaries) {
444
return
445
}
446
447
// Remove default configuration, which is the release configuration, when
448
// we're actually building withGeckoBinaries. This makes `gradle install`
449
// install the withGeckoBinaries artifacts, not the release artifacts (which
450
// are withoutGeckoBinaries and not suitable for distribution.)
451
def Configuration archivesConfig = project.getConfigurations().getByName('archives')
452
archivesConfig.artifacts.removeAll { it.extension.equals('aar') }
453
454
// For now, ensure Kotlin is only used in tests.
455
android.sourceSets.all { sourceSet ->
456
if (sourceSet.name.startsWith('test') || sourceSet.name.startsWith('androidTest')) {
457
return
458
}
459
(sourceSet.java.srcDirs + sourceSet.kotlin.srcDirs).each {
460
if (!fileTree(it, { include '**/*.kt' }).empty) {
461
throw new GradleException("Kotlin used in non-test directory ${it.path}")
462
}
463
}
464
}
465
}
466
467
// Bug 1353055 - Strip 'vars' debugging information to agree with moz.build.
468
apply from: "${topsrcdir}/mobile/android/gradle/debug_level.gradle"
469
android.libraryVariants.all configureVariantDebugLevel
470
471
// There's nothing specific to the :geckoview project here -- this just needs to
472
// be somewhere where the Android plugin is available so that we can fish the
473
// path to "android.jar".
474
task("generateSDKBindings", type: JavaExec) {
475
classpath project(':annotations').jar.archivePath
476
classpath project(':annotations').compileJava.classpath
477
478
// To use the lint APIs: "Lint must be invoked with the System property
479
// com.android.tools.lint.bindir pointing to the ANDROID_SDK tools
480
// directory"
481
systemProperties = [
482
'com.android.tools.lint.bindir': "${android.sdkDirectory}/tools",
483
]
484
485
main = 'org.mozilla.gecko.annotationProcessors.SDKProcessor'
486
// We only want to generate bindings for the main framework JAR,
487
// but not any of the additional android.test libraries.
488
args android.bootClasspath.findAll { it.getName().startsWith('android.jar') }
489
args 16
490
args "${topobjdir}/widget/android/bindings"
491
492
// Configure the arguments at evaluation-time, not at configuration-time.
493
doFirst {
494
// From -Pgenerate_sdk_bindings_args=... on command line; missing in
495
// `android-gradle-dependencies` toolchain task.
496
if (project.hasProperty('generate_sdk_bindings_args')) {
497
args project.generate_sdk_bindings_args.split(';')
498
}
499
}
500
501
workingDir "${topsrcdir}/widget/android/bindings"
502
503
dependsOn project(':annotations').jar
504
}
505
506
apply plugin: 'org.mozilla.apilint'
507
508
apiLint {
509
// TODO: Change this to `org` after hiding org.mozilla.gecko
510
packageFilter = 'org.mozilla.geckoview'
511
changelogFileName = 'src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md'
512
skipClassesRegex = ['^org.mozilla.geckoview.BuildConfig$']
513
lintFilters = ['GV']
514
allowedPackages = [
515
'java',
516
'android',
517
'org.json',
518
'org.mozilla.geckoview',
519
]
520
}