summaryrefslogtreecommitdiffstats
path: root/mobile/android/gradle
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/gradle')
-rw-r--r--mobile/android/gradle/debug_level.gradle17
-rw-r--r--mobile/android/gradle/dotgradle-offline/gradle.properties3
-rw-r--r--mobile/android/gradle/dotgradle-offline/init.gradle4
-rw-r--r--mobile/android/gradle/dotgradle-online/gradle.properties3
-rw-r--r--mobile/android/gradle/dotgradle-online/init.gradle4
-rw-r--r--mobile/android/gradle/mach_env.gradle29
-rw-r--r--mobile/android/gradle/product_flavors.gradle17
-rw-r--r--mobile/android/gradle/with_gecko_binaries.gradle81
8 files changed, 158 insertions, 0 deletions
diff --git a/mobile/android/gradle/debug_level.gradle b/mobile/android/gradle/debug_level.gradle
new file mode 100644
index 0000000000..a9537da327
--- /dev/null
+++ b/mobile/android/gradle/debug_level.gradle
@@ -0,0 +1,17 @@
+/* -*- Mode: Groovy; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Bug 1353055 - Strip 'vars' debugging information to agree with moz.build.
+ext.configureVariantDebugLevel = { variant ->
+ // Like 'debug' or 'release'.
+ def buildType = variant.buildType.name
+
+ // The default is 'lines,source,vars', which includes debugging information
+ // that is quite large: roughly 500kb for Fennec. Therefore we remove
+ // 'vars' unless we're producing a debug build, where it is useful.
+ if (!'debug'.equals(buildType) || mozconfig.substs.MOZILLA_OFFICIAL) {
+ variant.javaCompileProvider.get().options.debugOptions.debugLevel = 'lines,source'
+ }
+}
diff --git a/mobile/android/gradle/dotgradle-offline/gradle.properties b/mobile/android/gradle/dotgradle-offline/gradle.properties
new file mode 100644
index 0000000000..3f77ec9a2f
--- /dev/null
+++ b/mobile/android/gradle/dotgradle-offline/gradle.properties
@@ -0,0 +1,3 @@
+// Per https://docs.gradle.org/current/userguide/build_environment.html, this
+// overrides the gradle.properties in topsrcdir.
+org.gradle.daemon=false
diff --git a/mobile/android/gradle/dotgradle-offline/init.gradle b/mobile/android/gradle/dotgradle-offline/init.gradle
new file mode 100644
index 0000000000..8f06472aed
--- /dev/null
+++ b/mobile/android/gradle/dotgradle-offline/init.gradle
@@ -0,0 +1,4 @@
+// From https://discuss.gradle.org/t/enable-offline-mode-using-gradle-properties/12134/2.
+startParameter.offline = true
+// Sadly, this doesn't work: see http://stackoverflow.com/a/19686585.
+// startParameter.logLevel = org.gradle.api.logging.LogLevel.INFO
diff --git a/mobile/android/gradle/dotgradle-online/gradle.properties b/mobile/android/gradle/dotgradle-online/gradle.properties
new file mode 100644
index 0000000000..3f77ec9a2f
--- /dev/null
+++ b/mobile/android/gradle/dotgradle-online/gradle.properties
@@ -0,0 +1,3 @@
+// Per https://docs.gradle.org/current/userguide/build_environment.html, this
+// overrides the gradle.properties in topsrcdir.
+org.gradle.daemon=false
diff --git a/mobile/android/gradle/dotgradle-online/init.gradle b/mobile/android/gradle/dotgradle-online/init.gradle
new file mode 100644
index 0000000000..dbba0e3da5
--- /dev/null
+++ b/mobile/android/gradle/dotgradle-online/init.gradle
@@ -0,0 +1,4 @@
+// From https://discuss.gradle.org/t/enable-offline-mode-using-gradle-properties/12134/2.
+startParameter.offline = false
+// Sadly, this doesn't work: see http://stackoverflow.com/a/19686585.
+// startParameter.logLevel = org.gradle.api.logging.LogLevel.INFO
diff --git a/mobile/android/gradle/mach_env.gradle b/mobile/android/gradle/mach_env.gradle
new file mode 100644
index 0000000000..560d7dac22
--- /dev/null
+++ b/mobile/android/gradle/mach_env.gradle
@@ -0,0 +1,29 @@
+ext.machEnv = { topsrcdir ->
+ // Allow to specify mozconfig in `local.properties` via
+ // `mozilla-central.mozconfig=/path/to/mozconfig`. This can't be an environment
+ // variable because it's not feasible to specify environment variables under
+ // Android Studio on some platforms including macOS.
+ def localProperties = new Properties()
+ def localPropertiesFile = new File(topsrcdir, 'local.properties')
+ if (localPropertiesFile.canRead()) {
+ localPropertiesFile.withInputStream {
+ localProperties.load(it)
+ logger.lifecycle("settings.gradle> Read local.properties: ${localPropertiesFile}")
+ }
+ }
+
+ def localMozconfig = localProperties.getProperty("mozilla-central.mozconfig")
+
+ def env = System.env.collect { k, v -> "${k}=${v}" }
+ if (localMozconfig) {
+ def envMozconfig = System.env.get('FOUND_MOZCONFIG')
+ if (!envMozconfig || localMozconfig == envMozconfig) {
+ logger.lifecycle("settings.gradle> Setting mozconfig from local.properties: ${localMozconfig}")
+ env << "MOZCONFIG=${localMozconfig}"
+ } else {
+ logger.lifecycle("settings.gradle> Preferring mozconfig set in mach environment to mozconfig set in local.properties: ${envMozconfig}")
+ }
+ }
+
+ return env
+}
diff --git a/mobile/android/gradle/product_flavors.gradle b/mobile/android/gradle/product_flavors.gradle
new file mode 100644
index 0000000000..6278d9ff3f
--- /dev/null
+++ b/mobile/android/gradle/product_flavors.gradle
@@ -0,0 +1,17 @@
+/* -*- Mode: Groovy; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+ext.configureProductFlavors = {
+ flavorDimensions "geckoBinaries"
+ productFlavors {
+ withGeckoBinaries {
+ dimension "geckoBinaries"
+ }
+
+ withoutGeckoBinaries {
+ dimension "geckoBinaries"
+ }
+ }
+}
diff --git a/mobile/android/gradle/with_gecko_binaries.gradle b/mobile/android/gradle/with_gecko_binaries.gradle
new file mode 100644
index 0000000000..009a1f586e
--- /dev/null
+++ b/mobile/android/gradle/with_gecko_binaries.gradle
@@ -0,0 +1,81 @@
+/* -*- Mode: Groovy; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// The JNI wrapper generation tasks depend on the JAR creation task of the :annotations project.
+evaluationDependsOn(':annotations')
+
+// Whether to include compiled artifacts: `lib/**/*.so` and `assets/omni.ja`.
+// Multi-locale packaging wants to include compiled artifacts but *not* rebuild
+// them: see also `rootProject.{machStagePackage,geckoBinariesOnlyIf}`.
+def hasCompileArtifacts() {
+ return project.mozconfig.substs.COMPILE_ENVIRONMENT // Full builds.
+ || project.mozconfig.substs.MOZ_ARTIFACT_BUILDS // Artifact builds.
+ || System.getenv("MOZ_CHROME_MULTILOCALE") // Multi-locale packaging.
+}
+
+ext.configureVariantWithGeckoBinaries = { variant ->
+ if (hasCompileArtifacts()) {
+ // Local (read, not 'official') builds want to reflect developer changes to
+ // the omnijar sources, and (when compiling) to reflect developer changes to
+ // the native binaries. To do this, the Gradle build calls out to the
+ // moz.build system, which can be re-entrant. Official builds are driven by
+ // the moz.build system and should never be re-entrant in this way.
+ def assetGenTask = tasks.findByName("generate${variant.name.capitalize()}Assets")
+ def jniLibFoldersTask = tasks.findByName("merge${variant.name.capitalize()}JniLibFolders")
+ if (!mozconfig.substs.MOZILLA_OFFICIAL && (variant.productFlavors*.name).contains('withGeckoBinaries')) {
+ assetGenTask.dependsOn rootProject.machStagePackage
+ jniLibFoldersTask.dependsOn rootProject.machStagePackage
+ }
+ }
+}
+
+ext.configureLibraryVariantWithJNIWrappers = { variant, module ->
+ // BundleLibRuntime prepares the library for further processing to be
+ // incorporated in an app. We use this version to create the JNI wrappers.
+ def jarTask = tasks["bundleLibRuntimeToJar${variant.name.capitalize()}"]
+ def bundleJar = jarTask.outputs.files.find({ it.name == 'classes.jar' })
+
+ def annotationProcessorsJarTask = project(':annotations').jar
+
+ def wrapperTask
+ if (System.env.IS_LANGUAGE_REPACK == '1') {
+ // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and don't
+ // really have a build environment.
+ wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}")
+ } else {
+ wrapperTask = task("generateJNIWrappersFor${module}${variant.name.capitalize()}", type: JavaExec) {
+ classpath annotationProcessorsJarTask.archivePath
+
+ // Configure the classpath at evaluation-time, not at
+ // configuration-time: see above comment.
+ doFirst {
+ classpath variant.javaCompileProvider.get().classpath
+ }
+
+ mainClass = 'org.mozilla.gecko.annotationProcessors.AnnotationProcessor'
+ args module
+ args bundleJar
+
+ workingDir "${topobjdir}/widget/android"
+
+ inputs.file(bundleJar)
+ inputs.file(annotationProcessorsJarTask.archivePath)
+ inputs.property("module", module)
+
+ outputs.file("${topobjdir}/widget/android/GeneratedJNINatives.h")
+ outputs.file("${topobjdir}/widget/android/GeneratedJNIWrappers.cpp")
+ outputs.file("${topobjdir}/widget/android/GeneratedJNIWrappers.h")
+
+ dependsOn jarTask
+ dependsOn annotationProcessorsJarTask
+ }
+ }
+
+ if (module == 'Generated') {
+ tasks["bundle${variant.name.capitalize()}Aar"].dependsOn wrapperTask
+ } else {
+ tasks["assemble${variant.name.capitalize()}"].dependsOn wrapperTask
+ }
+}