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.4'
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 // Classfile, because javac has a bug with MethodParameters attributes
115 // with Java 7. https://bugs.openjdk.java.net/browse/JDK-8190452
117 // Turn all remaining warnings into errors,
118 // unless marked by @SuppressWarnings.
121 if (project.name == 'app') {
122 tasks.withType(JavaCompile) {
123 // Turn off classfile warnings because upon updating to play services 15.0.0
124 // a warning is being thrown from play-services-base which fails the build
125 // (com/google/android/gms/common/api/GoogleApiClient.class):
126 // warning: Cannot find annotation method 'value()' in type 'GuardedBy':
127 // class file for javax.annotation.concurrent.GuardedBy not found
128 options.compilerArgs += ["-Xlint:-classfile"]
133 if (!hasProperty('android')) {
136 android.applicationVariants.all {
137 preBuild.dependsOn rootProject.generateCodeAndResources
139 android.libraryVariants.all {
140 preBuild.dependsOn rootProject.generateCodeAndResources
149 languageLevel = '1.8'
153 // Object directories take a huge amount of time for IntelliJ to index.
154 // Exclude them. Convention is that object directories start with obj.
155 // IntelliJ is clever and will not exclude the parts of the object
156 // directory that are referenced, if there are any. In practice,
157 // indexing the entirety of the tree is taking too long, so exclude all
159 def topsrcdirURI = file(topsrcdir).toURI()
160 excludeDirs += files(file(topsrcdir)
161 .listFiles({it.isDirectory()} as FileFilter)
162 .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
163 .findAll({!it.equals('mobile/')}))
165 // If topobjdir is below topsrcdir, hide only some portions of that tree.
166 def topobjdirURI = file(topobjdir).toURI()
167 if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
168 excludeDirs -= file(topobjdir)
169 excludeDirs += files(file(topobjdir).listFiles())
170 excludeDirs -= file("${topobjdir}/gradle")
173 if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
174 excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
179 task wrapper(type: Wrapper) {