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 ->
47 // For in tree plugins.
49 url "file://${gradle.mozconfig.topsrcdir}/mobile/android/gradle/m2repo"
53 ext.kotlin_version = '1.2.41'
54 ext.support_library_version = '26.1.0'
55 ext.jacoco_version = '0.8.1'
57 if (gradle.mozconfig.substs.MOZ_ANDROID_GOOGLE_PLAY_SERVICES) {
58 ext.google_play_services_version = '15.0.1'
62 classpath 'com.android.tools.build:gradle:3.1.0'
63 classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
64 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
68 if ('multi' == System.env.AB_CD) {
69 // Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale. This
72 // |mach build| > |mach gradle| > |make gradle-targets| > AndroidManifest.xml > strings.xml > multi/brand.dtd
74 // dependency chain to fail, since multi isn't a real locale. To avoid
75 // this, if Gradle is invoked with AB_CD=multi, we don't invoke Make at all.
76 task generateCodeAndResources()
77 } else if (System.env.IS_LANGUAGE_REPACK == '1') {
78 // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource
79 // and code generation themselves.
80 task generateCodeAndResources()
82 task generateCodeAndResources(type:Exec) {
83 workingDir "${topobjdir}"
85 commandLine mozconfig.substs.GMAKE
87 args "${topobjdir}/mobile/android/base"
90 // Only show the output if something went wrong.
91 ignoreExitValue = true
92 standardOutput = new ByteArrayOutputStream()
93 errorOutput = standardOutput
95 if (execResult.exitValue != 0) {
96 throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${execResult.exitValue}:\n\n${standardOutput.toString()}")
103 subprojects { project ->
104 if (project.name != 'thirdparty') {
105 tasks.withType(JavaCompile) {
106 // Add compiler args for all code except third-party code.
107 options.compilerArgs += [
108 // Turn on all warnings, except...
110 // Deprecation, because we do use deprecated API for compatibility.
111 "-Xlint:-deprecation",
112 // Serial, because we don't use Java serialization.
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.7'
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) {