Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Gradle setup template with the common dependencies and settings
// Project-level config
import buildsrc.Libraries
import buildsrc.Versions
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath Libraries.Gradle.android
classpath Libraries.Gradle.fabric
classpath Libraries.Gradle.google_services
classpath Libraries.Gradle.kotlin
/*
* Temporary workaround for using latest Dagger versions with Jetifier.
* See https://issuetracker.google.com/115738511
*/
classpath 'com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta02'
}
}
plugins {
id 'com.diffplug.gradle.spotless' version '3.16.0'
id 'com.github.ben-manes.versions' version '0.20.0'
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' } // Used by simple-stack
}
afterEvaluate {
if (project.plugins.hasPlugin('kotlin-kapt')) {
kapt {
useBuildCache = true
correctErrorTypes = true
mapDiagnosticLocations = true
// Increase maximum number of printed errors
javacOptions {
option('-Xmaxerrs', 500)
}
// Disable generated code formatting and enable incremental builds for Dagger
arguments {
arg('dagger.formatGeneratedSource', 'disabled')
arg('dagger.gradle.incremental', 'enabled')
}
}
}
}
}
subprojects {
apply plugin: 'com.diffplug.gradle.spotless'
spotless {
kotlin {
target '**/*.kt'
ktlint(Versions.ktlint).userData(['indent_size': '2'])
licenseHeaderFile file('../spotless/copyright.kt')
endWithNewline()
}
}
}
// Config for app module
import buildsrc.BuildConfig
import buildsrc.Libraries
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
androidExtensions {
experimental = true
}
if (file('google-services.json').exists()) {
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
}
android {
compileSdkVersion BuildConfig.targetSdk
buildToolsVersion BuildConfig.buildTools
defaultConfig {
applicationId 'com.crushingdigits.releasenotifier'
minSdkVersion BuildConfig.minSdk
targetSdkVersion BuildConfig.targetSdk
versionCode 1
versionName '1.0'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
signingConfigs {
debug {
storeFile file('../signing/app-debug.jks')
storePassword 'password'
keyAlias 'debug'
keyPassword 'password'
}
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(file('../signing/keystore.properties')))
release {
storeFile file('../signing/app-release.jks')
storePassword keystoreProperties['keystorePassword']
keyAlias 'app-release'
keyPassword keystoreProperties['keyPassword']
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
minifyEnabled false
}
release {
signingConfig signingConfigs.release
shrinkResources true
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions.unitTests.includeAndroidResources = true
packagingOptions {
// Exclude AndroidX version files
exclude 'META-INF/*.version'
// Exclude consumer proguard files
exclude 'META-INF/proguard/*'
// Exclude the Firebase/Fabric/other random properties files
exclude '**/*.properties'
}
/*
* Temporary workaround for using latest Dagger versions with Jetifier.
* See https://issuetracker.google.com/115738511
*/
configurations.all {
resolutionStrategy.force 'com.android.tools.build.jetifier:jetifier-core:1.0.0-beta02'
}
}
dependencies {
testImplementation 'junit:junit:4.12'
testImplementation Libraries.mockito
testImplementation Libraries.mockito_kotlin
testImplementation Libraries.robolectric
testImplementation Libraries.AndroidX.lifecycle_test
testImplementation Libraries.AndroidX.room_test
testImplementation Libraries.AndroidX.work_test
// Dependencies for running Espresso on local JVM using Robolectric
testImplementation Libraries.AndroidX.Test.core
testImplementation Libraries.AndroidX.Test.espresso_accessibility
testImplementation Libraries.AndroidX.Test.espresso_contrib
testImplementation Libraries.AndroidX.Test.espresso_core
testImplementation Libraries.AndroidX.Test.espresso_idling_concurrent
testImplementation Libraries.AndroidX.Test.espresso_idling_resource
testImplementation Libraries.AndroidX.Test.espresso_intents
testImplementation Libraries.AndroidX.Test.espresso_web
testImplementation Libraries.AndroidX.Test.junit
testImplementation Libraries.AndroidX.Test.rules
testImplementation Libraries.AndroidX.Test.runner
testImplementation Libraries.AndroidX.Test.truth
androidTestUtil Libraries.AndroidX.Test.orchestrator
androidTestImplementation Libraries.mockito_android
androidTestImplementation Libraries.AndroidX.navigation_test
androidTestImplementation Libraries.AndroidX.Test.core
androidTestImplementation Libraries.AndroidX.Test.espresso_accessibility
androidTestImplementation Libraries.AndroidX.Test.espresso_contrib
androidTestImplementation Libraries.AndroidX.Test.espresso_core
androidTestImplementation Libraries.AndroidX.Test.espresso_idling_concurrent
androidTestImplementation Libraries.AndroidX.Test.espresso_idling_resource
androidTestImplementation Libraries.AndroidX.Test.espresso_intents
androidTestImplementation Libraries.AndroidX.Test.espresso_web
androidTestImplementation Libraries.AndroidX.Test.junit
androidTestImplementation Libraries.AndroidX.Test.rules
androidTestImplementation Libraries.AndroidX.Test.runner
androidTestImplementation Libraries.AndroidX.Test.truth
implementation Libraries.AndroidX.appcompat
implementation Libraries.AndroidX.browser
implementation Libraries.AndroidX.constraint_layout
implementation Libraries.AndroidX.core_ktx
implementation Libraries.AndroidX.multidex
implementation Libraries.AndroidX.recyclerview
implementation Libraries.AndroidX.work
implementation Libraries.AndroidX.lifecycle_extensions
implementation Libraries.AndroidX.lifecycle_reactivestreams
kapt Libraries.AndroidX.lifecycle_compiler
implementation Libraries.AndroidX.navigation_fragment
implementation Libraries.AndroidX.navigation_ui
implementation Libraries.AndroidX.paging_runtime
implementation Libraries.AndroidX.paging_rxjava
implementation Libraries.AndroidX.room_runtime
implementation Libraries.AndroidX.room_rxjava
kapt Libraries.AndroidX.room_compiler
implementation Libraries.Firebase.ads
implementation Libraries.Firebase.appindexing
implementation Libraries.Firebase.auth
implementation Libraries.Firebase.config
implementation Libraries.Firebase.core
implementation (Libraries.Firebase.crashlytics) {
transitive = true
}
implementation Libraries.Firebase.dynamic_links
implementation Libraries.Firebase.firestore
implementation Libraries.Firebase.functions
implementation Libraries.Firebase.inapp_messaging_display
implementation Libraries.Firebase.invites
implementation Libraries.Firebase.messaging
implementation Libraries.Firebase.ml_image_label
implementation Libraries.Firebase.ml_model_interpreter
implementation Libraries.Firebase.ml_vision
implementation Libraries.Firebase.perf
implementation Libraries.Firebase.storage
implementation Libraries.android_job
implementation Libraries.anko_commons
implementation Libraries.anko_design_coroutines
implementation Libraries.anko_design_listeners
implementation Libraries.anko_sdk15_coroutines
implementation Libraries.anko_sdk15_listeners
compileOnly Libraries.assisted_inject
kapt Libraries.assisted_inject_processor
implementation Libraries.butterknife
kapt Libraries.butterknife_compiler
implementation Libraries.coroutines
implementation Libraries.coroutines_android
implementation Libraries.coroutines_rx
implementation Libraries.dagger
kapt Libraries.dagger_compiler
implementation Libraries.epoxy
implementation Libraries.epoxy_databinding
implementation Libraries.epoxy_paging
kapt Libraries.epoxy_processor
implementation Libraries.eventbus
implementation Libraries.fresco
implementation Libraries.fresco_animated_gif
implementation Libraries.fresco_animated_webp
implementation Libraries.fresco_webpsupport
implementation Libraries.glide
kapt Libraries.glide_compiler
implementation Libraries.kotlin
debugImplementation Libraries.leakcanary
releaseImplementation Libraries.leakcanary_no_op
implementation Libraries.material_design
implementation Libraries.material_dialogs
implementation Libraries.moshi
kapt Libraries.moshi_codegen
implementation Libraries.mvrx
implementation Libraries.okhttp
implementation Libraries.okio
implementation Libraries.retrofit
implementation Libraries.retrofit_coroutines
implementation Libraries.retrofit_moshi
implementation Libraries.retrofit_rxjava2
implementation Libraries.rxandroid
implementation Libraries.rxjava
implementation Libraries.rxkotlin
debugImplementation Libraries.rxlint
implementation Libraries.simple_stack
implementation Libraries.threetenabp
implementation Libraries.timber
}
// Config for buildSrc module
import org.gradle.kotlin.dsl.`kotlin-dsl`
plugins {
`kotlin-dsl`
}
repositories {
jcenter()
}
// This file is placed in buildSrc module
@file:Suppress("MayBeConstant")
package buildsrc
@Suppress("unused")
object BuildConfig {
val buildTools = "28.0.3"
val minSdk = 17
val targetSdk = 28
val compileSdk = 28
}
object Versions {
object AndroidX {
val appcompat = "1.0.1"
val browser = "1.0.0"
val constraint_layout = "1.1.3"
val core_ktx = "1.0.1"
val lifecycle = "2.0.0"
val multidex = "2.0.0"
val navigation = "1.0.0-alpha07"
val paging = "2.1.0-beta01"
val recyclerview = "1.0.0"
val room = "2.1.0-alpha02"
val work = "1.0.0-alpha10"
object Test {
val core = "1.0.0"
val espresso = "3.1.0"
val junit = "1.0.0"
val rules = "1.1.0"
val runner = "1.1.0"
val truth = "1.0.0"
}
}
object Gradle {
val android = "3.2.1"
val fabric = "1.26.1"
val google_services = "4.2.0"
}
object Firebase {
val ads = "17.0.0"
val appindexing = "16.0.2"
val auth = "16.0.5"
val config = "16.1.0"
val core = "16.0.4"
val crashlytics = "2.9.6@aar"
val database = "16.0.4"
val dynamic_links = "16.1.2"
val firestore = "17.1.2"
val functions = "16.1.2"
val inapp_messaging = "17.0.3"
val inapp_messaging_display = "17.0.3"
val invites = "16.0.4"
val messaging = "17.3.4"
val ml_model_interpreter = "16.2.3"
val ml_vision = "18.0.1"
val ml_vision_image_label = "17.0.2"
val perf = "16.2.0"
val storage = "16.0.4"
}
val android_job = "1.2.6"
val anko = "0.10.7"
val assisted_inject = "0.3.0"
val butterknife = "9.0.0-rc1"
val coroutines = "1.0.0"
val dagger = "2.19"
val epoxy = "3.0.0-rc1"
val eventbus = "3.1.1"
val glide = "4.8.0"
val kotlin = "1.3.0"
@Suppress("unused") val ktlint = "0.29.0"
val leakcanary = "1.6.2"
val material_design = "1.0.0"
val material_dialogs = "2.0.0-beta4"
val mockito = "2.22.0" // Pinning this due to https://github.com/mockito/mockito/issues/1511
val mockito_kotlin = "2.0.0"
val moshi = "1.7.0"
val mvrx = "0.6.0"
val okhttp = "3.11.0"
val okio = "2.0.0" // Pinning this due to https://github.com/square/okio/issues/516
val retrofit = "2.4.0"
val robolectric = "4.0.1"
val rxandroid = "2.1.0"
val rxjava = "2.2.3"
val rxkotlin = "2.3.0"
val rxlint = "1.7.1"
val simple_stack = "1.13.0"
val threetenabp = "1.1.1"
val timber = "4.7.1"
}
@Suppress("unused")
object Libraries {
object AndroidX {
val appcompat = "androidx.appcompat:appcompat:${Versions.AndroidX.appcompat}"
val browser = "androidx.browser:browser:${Versions.AndroidX.browser}"
val constraint_layout = "androidx.constraintlayout:constraintlayout:${Versions.AndroidX.constraint_layout}"
val core_ktx = "androidx.core:core-ktx:${Versions.AndroidX.core_ktx}"
val lifecycle_compiler = "androidx.lifecycle:lifecycle-compiler:${Versions.AndroidX.lifecycle}"
val lifecycle_extensions = "androidx.lifecycle:lifecycle-extensions:${Versions.AndroidX.lifecycle}"
val lifecycle_reactivestreams = "androidx.lifecycle:lifecycle-reactivestreams-ktx:${Versions.AndroidX.lifecycle}"
val lifecycle_test = "androidx.arch.core:core-testing:${Versions.AndroidX.lifecycle}"
val multidex = "androidx.multidex:multidex:${Versions.AndroidX.multidex}"
val navigation_fragment = "android.arch.navigation:navigation-fragment-ktx:${Versions.AndroidX.navigation}"
val navigation_ui = "android.arch.navigation:navigation-ui-ktx:${Versions.AndroidX.navigation}"
val navigation_test = "android.arch.navigation:navigation-testing:${Versions.AndroidX.navigation}"
val paging_runtime = "androidx.paging:paging-runtime-ktx:${Versions.AndroidX.paging}"
val paging_rxjava = "androidx.paging:paging-rxjava2-ktx:${Versions.AndroidX.paging}"
val recyclerview = "androidx.recyclerview:recyclerview:${Versions.AndroidX.recyclerview}"
val room_compiler = "androidx.room:room-compiler:${Versions.AndroidX.room}"
val room_runtime = "androidx.room:room-runtime:${Versions.AndroidX.room}"
val room_rxjava = "androidx.room:room-rxjava2:${Versions.AndroidX.room}"
val room_test = "androidx.room:room-testing:${Versions.AndroidX.room}"
val work = "android.arch.work:work-runtime-ktx:${Versions.AndroidX.work}"
val work_test = "android.arch.work:work-testing:${Versions.AndroidX.work}"
object Test {
val core = "androidx.test:core:${Versions.AndroidX.Test.core}"
val espresso_accessibility = "androidx.test.espresso:espresso-accessibility:${Versions.AndroidX.Test.espresso}"
val espresso_contrib = "androidx.test.espresso:espresso-contrib:${Versions.AndroidX.Test.espresso}"
val espresso_core = "androidx.test.espresso:espresso-core:${Versions.AndroidX.Test.espresso}"
val espresso_idling_concurrent = "androidx.test.espresso.idling:idling-concurrent:${Versions.AndroidX.Test.espresso}"
val espresso_idling_resource = "androidx.test.espresso:espresso-idling-resource:${Versions.AndroidX.Test.espresso}"
val espresso_intents = "androidx.test.espresso:espresso-intents:${Versions.AndroidX.Test.espresso}"
val espresso_web = "androidx.test.espresso:espresso-web:${Versions.AndroidX.Test.espresso}"
val junit = "androidx.test.ext:junit:${Versions.AndroidX.Test.junit}"
val rules = "androidx.test:rules:${Versions.AndroidX.Test.rules}"
val runner = "androidx.test:runner:${Versions.AndroidX.Test.runner}"
val truth = "androidx.test.ext:truth:${Versions.AndroidX.Test.truth}"
}
}
object Gradle {
val android = "com.android.tools.build:gradle:${Versions.Gradle.android}"
val fabric = "io.fabric.tools:gradle:${Versions.Gradle.fabric}"
val google_services = "com.google.gms:google-services:${Versions.Gradle.google_services}"
val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
}
object Firebase {
val ads = "com.google.firebase:firebase-ads:${Versions.Firebase.ads}"
val appindexing = "com.google.firebase:firebase-appindexing:${Versions.Firebase.appindexing}"
val auth = "com.google.firebase:firebase-auth:${Versions.Firebase.auth}"
val config = "com.google.firebase:firebase-config:${Versions.Firebase.config}"
val core = "com.google.firebase:firebase-core:${Versions.Firebase.core}"
val crashlytics = "com.crashlytics.sdk.android:crashlytics:${Versions.Firebase.crashlytics}"
val database = "com.google.firebase:firebase-database:${Versions.Firebase.database}"
val dynamic_links = "com.google.firebase:firebase-dynamic-links:${Versions.Firebase.dynamic_links}"
val firestore = "com.google.firebase:firebase-firestore:${Versions.Firebase.firestore}"
val functions = "com.google.firebase:firebase-functions:${Versions.Firebase.functions}"
val inapp_messaging = "com.google.firebase:firebase-inappmessaging:${Versions.Firebase.inapp_messaging}"
val inapp_messaging_display = "com.google.firebase:firebase-inappmessaging-display:${Versions.Firebase.inapp_messaging_display}"
val invites = "com.google.firebase:firebase-invites:${Versions.Firebase.invites}"
val messaging = "com.google.firebase:firebase-messaging:${Versions.Firebase.messaging}"
val ml_model_interpreter = "com.google.firebase:firebase-ml-model-interpreter:${Versions.Firebase.ml_model_interpreter}"
val ml_vision = "com.google.firebase:firebase-ml-vision:${Versions.Firebase.ml_vision}"
val ml_vision_image_label = "com.google.firebase:firebase-ml-vision-image-label-model:${Versions.Firebase.ml_vision_image_label}"
val perf = "com.google.firebase:firebase-perf:${Versions.Firebase.perf}"
val storage = "com.google.firebase:firebase-storage:${Versions.Firebase.storage}"
}
val android_job = "com.evernote:android-job:${Versions.android_job}"
val anko_commons = "org.jetbrains.anko:anko-commons:${Versions.anko}"
val anko_design_coroutines = "org.jetbrains.anko:anko-design-coroutines:${Versions.anko}"
val anko_design_listeners = "org.jetbrains.anko:anko-design-listeners:${Versions.anko}"
val anko_sdk15_coroutines = "org.jetbrains.anko:anko-sdk15-coroutines:${Versions.anko}"
val anko_sdk15_listeners = "org.jetbrains.anko:anko-sdk15-listeners:${Versions.anko}"
val assisted_inject = "com.squareup.inject:assisted-inject-annotations-dagger2:${Versions.assisted_inject}"
val assisted_inject_processor = "com.squareup.inject:assisted-inject-processor-dagger2:${Versions.assisted_inject}"
val butterknife = "com.jakewharton:butterknife:${Versions.butterknife}"
val butterknife_compiler = "com.jakewharton:butterknife-compiler:${Versions.butterknife}"
val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}"
val coroutines_android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutines}"
val coroutines_rx = "org.jetbrains.kotlinx:kotlinx-coroutines-rx2:${Versions.coroutines}"
val dagger = "com.google.dagger:dagger:${Versions.dagger}"
val dagger_compiler = "com.google.dagger:dagger-compiler:${Versions.dagger}"
val epoxy = "com.airbnb.android:epoxy:${Versions.epoxy}"
val epoxy_databinding = "com.airbnb.android:epoxy-databinding:${Versions.epoxy}"
val epoxy_paging = "com.airbnb.android:epoxy-paging:${Versions.epoxy}"
val epoxy_processor = "com.airbnb.android:epoxy-processor:${Versions.epoxy}"
val eventbus = "org.greenrobot:eventbus:${Versions.eventbus}"
val glide = "com.github.bumptech.glide:glide:${Versions.glide}"
val glide_compiler = "com.github.bumptech.glide:compiler:${Versions.glide}"
val kotlin = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${Versions.kotlin}"
val leakcanary = "com.squareup.leakcanary:leakcanary-android:${Versions.leakcanary}"
val leakcanary_no_op = "com.squareup.leakcanary:leakcanary-android-no-op:${Versions.leakcanary}"
val material_design = "com.google.android.material:material:${Versions.material_design}"
val material_dialogs = "com.afollestad.material-dialogs:core:${Versions.material_dialogs}"
val mockito = "org.mockito:mockito-core:${Versions.mockito}"
val mockito_android = "org.mockito:mockito-android:${Versions.mockito}"
val mockito_kotlin = "com.nhaarman.mockitokotlin2:mockito-kotlin:${Versions.mockito_kotlin}"
val moshi = "com.squareup.moshi:moshi:${Versions.moshi}"
val moshi_codegen = "com.squareup.moshi:moshi-kotlin-codegen:${Versions.moshi}"
val mvrx = "com.airbnb.android:mvrx:${Versions.mvrx}"
val okhttp = "com.squareup.okhttp3:okhttp:${Versions.okhttp}"
val okio = "com.squareup.okio:okio:${Versions.okio}"
val retrofit = "com.squareup.retrofit2:retrofit:${Versions.retrofit}"
val retrofit_rxjava = "com.squareup.retrofit2:adapter-rxjava2:${Versions.retrofit}"
val robolectric = "org.robolectric:robolectric:${Versions.robolectric}"
val rxandroid = "io.reactivex.rxjava2:rxandroid:${Versions.rxandroid}"
val rxjava = "io.reactivex.rxjava2:rxjava:${Versions.rxjava}"
val rxkotlin = "io.reactivex.rxjava2:rxkotlin:${Versions.rxkotlin}"
val rxlint = "nl.littlerobots.rxlint:rxlint:${Versions.rxlint}"
val simple_stack = "com.github.Zhuinden:simple-stack:${Versions.simple_stack}"
val threetenabp = "com.jakewharton.threetenabp:threetenabp:${Versions.threetenabp}"
val timber = "com.jakewharton.timber:timber:${Versions.timber}"
}
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true
org.gradle.caching=true
# AndroidX
android.useAndroidX=true
android.enableJetifier=true
# Enable Robolectric to use the same resources as Android
android.enableUnitTestBinaryResources=true
@qwertyfinger

This comment has been minimized.

Copy link
Owner Author

qwertyfinger commented Nov 6, 2018

Using this template allows to grab specific dependencies for Android project as you need them relatively quickly.

buildSrc module with Kotlin Gradle DSL is used to enable auto-completion and going to declaration site for more easy and convenient dependency management.

Available libraries and tools

Gradle Plugins

Android Jetpack

AndroidX Test

Other Testing Libraries

Firebase

Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.