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 = '23.4.0'
56 if (gradle.mozconfig.substs.MOZ_ANDROID_GOOGLE_PLAY_SERVICES) {
57 ext.google_play_services_version = '8.4.0'
61 classpath 'com.android.tools.build:gradle:3.0.1'
62 classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
63 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
67 if ('multi' == System.env.AB_CD) {
68 // Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale. This
71 // |mach build| > |mach gradle| > |make gradle-targets| > AndroidManifest.xml > strings.xml > multi/brand.dtd
73 // dependency chain to fail, since multi isn't a real locale. To avoid
74 // this, if Gradle is invoked with AB_CD=multi, we don't invoke Make at all.
75 task generateCodeAndResources()
76 } else if (System.env.IS_LANGUAGE_REPACK == '1') {
77 // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource
78 // and code generation themselves.
79 task generateCodeAndResources()
81 task generateCodeAndResources(type:Exec) {
82 workingDir "${topobjdir}"
84 commandLine mozconfig.substs.GMAKE
86 args "${topobjdir}/mobile/android/base"
89 // Only show the output if something went wrong.
90 ignoreExitValue = true
91 standardOutput = new ByteArrayOutputStream()
92 errorOutput = standardOutput
94 if (execResult.exitValue != 0) {
95 throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${execResult.exitValue}:\n\n${standardOutput.toString()}")
102 subprojects { project ->
103 if (project.name != 'thirdparty') {
104 tasks.withType(JavaCompile) {
105 // Add compiler args for all code except third-party code.
106 options.compilerArgs += [
107 // Turn on all warnings, except...
109 // Deprecation, because we do use deprecated API for compatibility.
110 "-Xlint:-deprecation",
111 // Serial, because we don't use Java serialization.
113 // Turn all remaining warnings into errors,
114 // unless marked by @SuppressWarnings.
119 if (!hasProperty('android')) {
122 android.applicationVariants.all {
123 preBuild.dependsOn rootProject.generateCodeAndResources
125 android.libraryVariants.all {
126 preBuild.dependsOn rootProject.generateCodeAndResources
135 languageLevel = '1.7'
139 // Object directories take a huge amount of time for IntelliJ to index.
140 // Exclude them. Convention is that object directories start with obj.
141 // IntelliJ is clever and will not exclude the parts of the object
142 // directory that are referenced, if there are any. In practice,
143 // indexing the entirety of the tree is taking too long, so exclude all
145 def topsrcdirURI = file(topsrcdir).toURI()
146 excludeDirs += files(file(topsrcdir)
147 .listFiles({it.isDirectory()} as FileFilter)
148 .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
149 .findAll({!it.equals('mobile/')}))
151 // If topobjdir is below topsrcdir, hide only some portions of that tree.
152 def topobjdirURI = file(topobjdir).toURI()
153 if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
154 excludeDirs -= file(topobjdir)
155 excludeDirs += files(file(topobjdir).listFiles())
156 excludeDirs -= file("${topobjdir}/gradle")
159 if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
160 excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
165 task wrapper(type: Wrapper) {