Revision control

Copy as Markdown

/* 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/. */
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$project.rootDir/automation/gradle/versionCode.gradle"
import com.android.build.gradle.internal.tasks.AppPreBuildTask
import com.android.build.OutputFile
android {
compileSdkVersion Config.compileSdkVersion
defaultConfig {
applicationId "org.mozilla.reference.browser"
minSdkVersion Config.minSdkVersion
compileSdkVersion Config.compileSdkVersion
targetSdkVersion Config.targetSdkVersion
versionCode 1
versionName Config.generateDebugVersionName()
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
}
def releaseTemplate = {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
matchingFallbacks = ['release'] // Use on the "release" build type in dependencies (AARs)
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion = Versions.google_compose_compiler
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
raptor releaseTemplate >> { // the ">>" concatenates the raptor-specific options with the template
applicationIdSuffix ".raptor"
manifestPlaceholders.isRaptorEnabled = "true"
matchingFallbacks = ['release']
}
nightly releaseTemplate >> {
buildConfigField "boolean", "IS_RELEASED", "true"
}
}
variantFilter { // There's a "release" build type that exists by default that we don't use (it's replaced by "nightly" and "beta")
if (buildType.name == 'release') {
setIgnore true
}
}
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
animationsDisabled = true
}
lintOptions {
lintConfig file("lint.xml")
baseline file("lint-baseline.xml")
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
packagingOptions {
exclude 'META-INF/atomicfu.kotlin_module'
}
splits {
abi {
enable true
reset()
include "x86", "armeabi-v7a", "arm64-v8a", "x86_64"
}
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
freeCompilerArgs += "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
freeCompilerArgs += "-Xjvm-default=all"
jvmTarget = "11"
}
}
def baseVersionCode = generatedVersionCode
android.applicationVariants.all { variant ->
// -------------------------------------------------------------------------------------------------
// Sentry: Read token from local file if it exists (Only release builds)
// -------------------------------------------------------------------------------------------------
print("Sentry token: "+ variant.name)
try {
def token = new File("${rootDir}/.sentry_token").text.trim()
buildConfigField 'String', 'SENTRY_TOKEN', '"' + token + '"'
println "(Added from .sentry_token file)"
} catch (FileNotFoundException ignored) {
buildConfigField 'String', 'SENTRY_TOKEN', 'null'
println(" :( ")
}
// -------------------------------------------------------------------------------------------------
// Activating crash reports with command line parameter.
// -------------------------------------------------------------------------------------------------
if (project.hasProperty("crashReportEnabled") && project.property("crashReportEnabled") == "true") {
buildConfigField 'boolean', 'CRASH_REPORTING_ENABLED', 'true'
} else {
buildConfigField 'boolean', 'CRASH_REPORTING_ENABLED', 'false'
}
// -------------------------------------------------------------------------------------------------
// Activating telemetry with command line paramter.
// -------------------------------------------------------------------------------------------------
if (project.hasProperty("telemetry") && project.property("telemetry") == "true") {
buildConfigField 'boolean', 'TELEMETRY_ENABLED', 'true'
} else {
buildConfigField 'boolean', 'TELEMETRY_ENABLED', 'false'
}
// -------------------------------------------------------------------------------------------------
// Generating version codes for Google Play
// -------------------------------------------------------------------------------------------------
if (variant.buildType.buildConfigFields['IS_RELEASED']?.value) {
// The Google Play Store does not allow multiple APKs for the same app that all have the
// same version code. Therefore we need to have different version codes for our ARM and x86
// builds.
// Our x86 builds need a higher version code to avoid installing ARM builds on an x86 device
// with ARM compatibility mode.
def versionName = Config.releaseVersionName(project)
variant.outputs.each { output ->
def abi = output.getFilter(OutputFile.ABI)
def versionCodeOverride = baseVersionCode
if (abi == "x86_64") {
versionCodeOverride = baseVersionCode + 3
} else if (abi == "x86") {
versionCodeOverride = baseVersionCode + 2
} else if (abi == "arm64-v8a") {
versionCodeOverride = baseVersionCode + 1
} else if (abi == "armeabi-v7a") {
versionCodeOverride = baseVersionCode
}
println("versionCode for $abi = $versionCodeOverride")
output.versionNameOverride = versionName
output.versionCodeOverride = versionCodeOverride
}
// If this is a release build, validate that "versionName" is set
tasks.withType(AppPreBuildTask) { prebuildTask ->
// You can't add a closure to a variant, so we need to look for an early variant-specific type
// of task (AppPreBuildTask is the first) and filter to make sure we're looking at the task for
// this variant that we're currently configuring
if (prebuildTask.variantName != variant.name) {
return
}
// Append to the task so the first thing it does is run our validation
prebuildTask.doFirst {
if (!project.hasProperty('versionName')) {
throw new RuntimeException("Release builds require the 'versionName' property to be set.\n" +
"If you're using an IDE, set your build variant to be a \"debug\" type.\n" +
"If you're using the command-line, either build a debug variant instead ('./gradlew assembleDebug')\n" +
"\tor continue building the release build and set the \"versionName\" property ('./gradlew -PversionName=<...> assembleNightly').")
// TODO when Android Studio 3.5.0 is prevalent, we can set the "debug" build type as the default
}
}
}
}
// -------------------------------------------------------------------------------------------------
// BuildConfig: Set flag for official builds; similar to MOZILLA_OFFICIAL in mozilla-central.
// -------------------------------------------------------------------------------------------------
if (project.hasProperty("official") || gradle.hasProperty("localProperties.official")) {
buildConfigField 'Boolean', 'MOZILLA_OFFICIAL', 'true'
} else {
buildConfigField 'Boolean', 'MOZILLA_OFFICIAL', 'false'
}
}
// Select the Glean from GeckoView.
// `service-sync-logins` requires Glean, which pulls in glean-native,
// but that's also provided by geckoview-omni, so now we need to select which one to use.
project.configurations.all {
resolutionStrategy.capabilitiesResolution.withCapability("org.mozilla.telemetry:glean-native") {
def toBeSelected = candidates.find { it.id instanceof ModuleComponentIdentifier && it.id.module.contains('geckoview') }
if (toBeSelected != null) {
select(toBeSelected)
}
because 'use GeckoView Glean instead of standalone Glean'
}
}
dependencies {
implementation Deps.mozilla_concept_awesomebar
implementation Deps.mozilla_concept_engine
implementation Deps.mozilla_concept_menu
implementation Deps.mozilla_concept_tabstray
implementation Deps.mozilla_concept_toolbar
implementation Deps.mozilla_concept_storage
implementation Deps.mozilla_concept_sync
implementation Deps.mozilla_concept_push
implementation Deps.mozilla_compose_awesomebar
implementation Deps.mozilla_browser_engine_gecko
implementation Deps.mozilla_browser_domains
implementation Deps.mozilla_browser_tabstray
implementation Deps.mozilla_browser_toolbar
implementation Deps.mozilla_browser_menu
implementation Deps.mozilla_browser_menu2
implementation Deps.mozilla_browser_session_storage
implementation Deps.mozilla_browser_state
implementation Deps.mozilla_browser_storage_sync
implementation Deps.mozilla_browser_icons
implementation Deps.mozilla_browser_thumbnails
implementation Deps.mozilla_feature_accounts
implementation Deps.mozilla_feature_accounts_push
implementation Deps.mozilla_feature_addons
implementation Deps.mozilla_feature_app_links
implementation Deps.mozilla_feature_awesomebar
implementation Deps.mozilla_feature_autofill
implementation Deps.mozilla_feature_contextmenu
implementation Deps.mozilla_feature_customtabs
implementation Deps.mozilla_feature_findinpage
implementation Deps.mozilla_feature_media
implementation Deps.mozilla_feature_sitepermissions
implementation Deps.mozilla_feature_intent
implementation Deps.mozilla_feature_search
implementation Deps.mozilla_feature_session
implementation Deps.mozilla_feature_toolbar
implementation Deps.mozilla_feature_tabs
implementation Deps.mozilla_feature_downloads
implementation Deps.mozilla_feature_prompts
implementation Deps.mozilla_feature_push
implementation Deps.mozilla_feature_pwa
implementation Deps.mozilla_feature_qr
implementation Deps.mozilla_feature_readerview
implementation Deps.mozilla_feature_syncedtabs
implementation Deps.mozilla_feature_webauthn
implementation Deps.mozilla_feature_webcompat
implementation Deps.mozilla_feature_webnotifications
implementation Deps.mozilla_ui_autocomplete
implementation Deps.mozilla_ui_colors
implementation Deps.mozilla_ui_icons
implementation Deps.mozilla_ui_tabcounter
implementation Deps.mozilla_service_firefox_accounts
implementation Deps.mozilla_service_location
implementation Deps.mozilla_service_sync_logins
implementation Deps.mozilla_support_images
implementation Deps.mozilla_support_utils
implementation Deps.mozilla_support_ktx
implementation Deps.mozilla_support_rustlog
implementation Deps.mozilla_support_rusthttp
implementation Deps.mozilla_support_webextensions
implementation Deps.mozilla_lib_crash
implementation Deps.mozilla_lib_crash_sentry
implementation Deps.mozilla_lib_push_firebase
implementation Deps.mozilla_lib_publicsuffixlist
implementation Deps.mozilla_lib_dataprotect
implementation Deps.thirdparty_sentry
implementation Deps.kotlin_coroutines
implementation Deps.androidx_appcompat
implementation Deps.androidx_core_ktx
implementation Deps.androidx_constraintlayout
implementation Deps.androidx_lifecycle_process
implementation Deps.androidx_preference_ktx
implementation Deps.androidx_swiperefreshlayout
implementation Deps.androidx_work_runtime_ktx
implementation Deps.androidx_activity_compose
implementation Deps.androidx_compose_ui
implementation Deps.androidx_compose_ui_tooling
implementation Deps.androidx_compose_foundation
implementation Deps.androidx_compose_material
implementation Deps.google_material
androidTestImplementation Deps.uiautomator
androidTestImplementation Deps.junit_ktx
androidTestImplementation Deps.espresso_core, {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestImplementation(Deps.espresso_contrib) {
exclude module: 'appcompat-v7'
exclude module: 'support-v4'
exclude module: 'support-annotations'
exclude module: 'recyclerview-v7'
exclude module: 'design'
exclude module: 'espresso-core'
}
androidTestImplementation Deps.espresso_idling_resources
androidTestImplementation Deps.espresso_web, {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestImplementation Deps.mockwebserver
androidTestImplementation Deps.tools_test_runner
androidTestImplementation Deps.tools_test_rules
androidTestUtil Deps.orchestrator
androidTestImplementation Deps.espresso_core, {
exclude group: 'com.android.support', module: 'support-annotations'
}
}
// -------------------------------------------------------------------------------------------------
// Task for printing APK information for the requested variant
// Usage: ./gradlew printVariants
// -------------------------------------------------------------------------------------------------
task printVariants {
doLast {
def variants = android.applicationVariants.collect { variant -> [
apks: variant.outputs.collect { output -> [
abi: output.getFilter(com.android.build.VariantOutput.FilterType.ABI),
fileName: output.outputFile.name
]},
build_type: variant.buildType.name,
name: variant.name,
]}
println 'variants: ' + groovy.json.JsonOutput.toJson(variants)
}
}
task printGeckoviewVersion {
doLast {
def configuration = configurations.implementationDependenciesMetadata
def dependencies = configuration.incoming.resolutionResult.allDependencies
def geckoviewDependency = dependencies.find { it.selected.id.moduleIdentifier.group == 'org.mozilla.geckoview' }
println('geckoviewVersion: ' + groovy.json.JsonOutput.toJson(geckoviewDependency.selected.moduleVersion.version))
}
}
if (gradle.hasProperty('localProperties.dependencySubstitutions.geckoviewTopsrcdir')) {
if (gradle.hasProperty('localProperties.dependencySubstitutions.geckoviewTopobjdir')) {
ext.topobjdir = gradle."localProperties.dependencySubstitutions.geckoviewTopobjdir"
}
ext.topsrcdir = gradle."localProperties.dependencySubstitutions.geckoviewTopsrcdir"
apply from: "${topsrcdir}/substitute-local-geckoview.gradle"
}
if (gradle.hasProperty('localProperties.autoPublish.android-components.dir')) {
ext.acSrcDir = gradle."localProperties.autoPublish.android-components.dir"
apply from: "../${acSrcDir}/substitute-local-ac.gradle"
}
if (gradle.hasProperty('localProperties.autoPublish.application-services.dir')) {
ext.appServicesSrcDir = gradle."localProperties.autoPublish.application-services.dir"
apply from: "../${appServicesSrcDir}/build-scripts/substitute-local-appservices.gradle"
}