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.1.51'
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()}")
103 if (!hasProperty('android')) {
106 android.applicationVariants.all {
107 preBuild.dependsOn rootProject.generateCodeAndResources
109 android.libraryVariants.all {
110 preBuild.dependsOn rootProject.generateCodeAndResources
119 languageLevel = '1.7'
123 // Object directories take a huge amount of time for IntelliJ to index.
124 // Exclude them. Convention is that object directories start with obj.
125 // IntelliJ is clever and will not exclude the parts of the object
126 // directory that are referenced, if there are any. In practice,
127 // indexing the entirety of the tree is taking too long, so exclude all
129 def topsrcdirURI = file(topsrcdir).toURI()
130 excludeDirs += files(file(topsrcdir)
131 .listFiles({it.isDirectory()} as FileFilter)
132 .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
133 .findAll({!it.equals('mobile/')}))
135 // If topobjdir is below topsrcdir, hide only some portions of that tree.
136 def topobjdirURI = file(topobjdir).toURI()
137 if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
138 excludeDirs -= file(topobjdir)
139 excludeDirs += files(file(topobjdir).listFiles())
140 excludeDirs -= file("${topobjdir}/gradle")
143 if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
144 excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
149 task wrapper(type: Wrapper) {