1 def tryInt = { string ->
5 if (string.isInteger()) {
6 return string as Integer
12 // Expose the per-object-directory configuration to all projects.
14 mozconfig = gradle.mozconfig
15 topsrcdir = gradle.mozconfig.topsrcdir
16 topobjdir = gradle.mozconfig.topobjdir
18 compileSdkVersion = tryInt(mozconfig.substs.ANDROID_COMPILE_SDK_VERSION)
19 targetSdkVersion = tryInt(mozconfig.substs.ANDROID_TARGET_SDK)
20 minSdkVersion = tryInt(mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION)
21 manifestPlaceholders = [
22 ANDROID_PACKAGE_NAME: mozconfig.substs.ANDROID_PACKAGE_NAME,
23 ANDROID_TARGET_SDK: mozconfig.substs.ANDROID_TARGET_SDK,
24 MOZ_ANDROID_MIN_SDK_VERSION: mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION,
25 MOZ_ANDROID_SHARED_ID: "${mozconfig.substs.ANDROID_PACKAGE_NAME}.sharedID",
30 gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
38 buildDir "${topobjdir}/gradle/build"
42 gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
49 ext.kotlin_version = '1.2.41'
50 ext.support_library_version = '26.1.0'
51 ext.jacoco_version = '0.8.1'
53 if (gradle.mozconfig.substs.MOZ_ANDROID_GOOGLE_PLAY_SERVICES) {
54 ext.google_play_services_version = '15.0.1'
58 classpath 'org.mozilla.apilint:apilint:0.1.4'
59 classpath 'com.android.tools.build:gradle:3.1.4'
60 classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
61 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
65 if ('multi' == System.env.AB_CD) {
66 // Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale. This
69 // |mach build| > |mach gradle| > |make gradle-targets| > AndroidManifest.xml > strings.xml > multi/brand.dtd
71 // dependency chain to fail, since multi isn't a real locale. To avoid
72 // this, if Gradle is invoked with AB_CD=multi, we don't invoke Make at all.
73 task generateCodeAndResources()
74 } else if (System.env.IS_LANGUAGE_REPACK == '1') {
75 // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource
76 // and code generation themselves.
77 task generateCodeAndResources()
79 task generateCodeAndResources(type:Exec) {
80 workingDir "${topobjdir}"
82 commandLine mozconfig.substs.GMAKE
84 args "${topobjdir}/mobile/android/base"
87 // Only show the output if something went wrong.
88 ignoreExitValue = true
89 standardOutput = new ByteArrayOutputStream()
90 errorOutput = standardOutput
92 if (execResult.exitValue != 0) {
93 throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${execResult.exitValue}:\n\n${standardOutput.toString()}")
100 subprojects { project ->
101 if (project.name != 'thirdparty') {
102 tasks.withType(JavaCompile) {
103 // Add compiler args for all code except third-party code.
104 options.compilerArgs += [
105 // Turn on all warnings, except...
107 // Deprecation, because we do use deprecated API for compatibility.
108 "-Xlint:-deprecation",
109 // Serial, because we don't use Java serialization.
111 // Classfile, because javac has a bug with MethodParameters attributes
112 // with Java 7. https://bugs.openjdk.java.net/browse/JDK-8190452
114 // Turn all remaining warnings into errors,
115 // unless marked by @SuppressWarnings.
118 if (project.name == 'app') {
119 tasks.withType(JavaCompile) {
120 // Turn off classfile warnings because upon updating to play services 15.0.0
121 // a warning is being thrown from play-services-base which fails the build
122 // (com/google/android/gms/common/api/GoogleApiClient.class):
123 // warning: Cannot find annotation method 'value()' in type 'GuardedBy':
124 // class file for javax.annotation.concurrent.GuardedBy not found
125 options.compilerArgs += ["-Xlint:-classfile"]
130 if (!hasProperty('android')) {
133 android.applicationVariants.all {
134 preBuild.dependsOn rootProject.generateCodeAndResources
136 android.libraryVariants.all {
137 preBuild.dependsOn rootProject.generateCodeAndResources
146 languageLevel = '1.8'
150 // Object directories take a huge amount of time for IntelliJ to index.
151 // Exclude them. Convention is that object directories start with obj.
152 // IntelliJ is clever and will not exclude the parts of the object
153 // directory that are referenced, if there are any. In practice,
154 // indexing the entirety of the tree is taking too long, so exclude all
156 def topsrcdirURI = file(topsrcdir).toURI()
157 excludeDirs += files(file(topsrcdir)
158 .listFiles({it.isDirectory()} as FileFilter)
159 .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
160 .findAll({!it.equals('mobile/')}))
162 // If topobjdir is below topsrcdir, hide only some portions of that tree.
163 def topobjdirURI = file(topobjdir).toURI()
164 if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
165 excludeDirs -= file(topobjdir)
166 excludeDirs += files(file(topobjdir).listFiles())
167 excludeDirs -= file("${topobjdir}/gradle")
170 if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
171 excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
176 task wrapper(type: Wrapper) {