1def tryInt = { string -> 2 if (string == null) { 3 return string 4 } 5 if (string.isInteger()) { 6 return string as Integer 7 } 8 return string 9} 10 11allprojects { 12 // Expose the per-object-directory configuration to all projects. 13 ext { 14 mozconfig = gradle.mozconfig 15 topsrcdir = gradle.mozconfig.topsrcdir 16 topobjdir = gradle.mozconfig.topobjdir 17 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", 26 ] 27 } 28 29 repositories { 30 gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository -> 31 maven { 32 url repository 33 } 34 } 35 } 36} 37 38buildDir "${topobjdir}/gradle/build" 39 40buildscript { 41 repositories { 42 gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository -> 43 maven { 44 url repository 45 } 46 } 47 // For in tree plugins. 48 maven { 49 url "file://${gradle.mozconfig.topsrcdir}/mobile/android/gradle/m2repo" 50 } 51 } 52 53 ext.kotlin_version = '1.1.51' 54 55 dependencies { 56 classpath 'com.android.tools.build:gradle:3.0.1' 57 classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2' 58 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 59 } 60} 61 62if ('multi' == System.env.AB_CD) { 63 // Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale. This 64 // causes the 65 // 66 // |mach build| > |mach gradle| > |make gradle-targets| > AndroidManifest.xml > strings.xml > multi/brand.dtd 67 // 68 // dependency chain to fail, since multi isn't a real locale. To avoid 69 // this, if Gradle is invoked with AB_CD=multi, we don't invoke Make at all. 70 task generateCodeAndResources() 71} else if (System.env.IS_LANGUAGE_REPACK == '1') { 72 // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource 73 // and code generation themselves. 74 task generateCodeAndResources() 75} else { 76 task generateCodeAndResources(type:Exec) { 77 workingDir "${topobjdir}" 78 79 commandLine mozconfig.substs.GMAKE 80 args '-C' 81 args "${topobjdir}/mobile/android/base" 82 args 'gradle-targets' 83 84 // Only show the output if something went wrong. 85 ignoreExitValue = true 86 standardOutput = new ByteArrayOutputStream() 87 errorOutput = standardOutput 88 doLast { 89 if (execResult.exitValue != 0) { 90 throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${execResult.exitValue}:\n\n${standardOutput.toString()}") 91 } 92 } 93 } 94} 95 96afterEvaluate { 97 subprojects { 98 if (!hasProperty('android')) { 99 return 100 } 101 android.applicationVariants.all { 102 preBuild.dependsOn rootProject.generateCodeAndResources 103 } 104 android.libraryVariants.all { 105 preBuild.dependsOn rootProject.generateCodeAndResources 106 } 107 } 108} 109 110apply plugin: 'idea' 111 112idea { 113 project { 114 languageLevel = '1.7' 115 } 116 117 module { 118 // Object directories take a huge amount of time for IntelliJ to index. 119 // Exclude them. Convention is that object directories start with obj. 120 // IntelliJ is clever and will not exclude the parts of the object 121 // directory that are referenced, if there are any. In practice, 122 // indexing the entirety of the tree is taking too long, so exclude all 123 // but mobile/. 124 def topsrcdirURI = file(topsrcdir).toURI() 125 excludeDirs += files(file(topsrcdir) 126 .listFiles({it.isDirectory()} as FileFilter) 127 .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths. 128 .findAll({!it.equals('mobile/')})) 129 130 // If topobjdir is below topsrcdir, hide only some portions of that tree. 131 def topobjdirURI = file(topobjdir).toURI() 132 if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) { 133 excludeDirs -= file(topobjdir) 134 excludeDirs += files(file(topobjdir).listFiles()) 135 excludeDirs -= file("${topobjdir}/gradle") 136 } 137 138 if (!mozconfig.substs.MOZ_INSTALL_TRACKING) { 139 excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust") 140 } 141 } 142} 143 144task wrapper(type: Wrapper) { 145} 146