Created
December 9, 2018 22:02
-
-
Save ghahramani/751cb251dbddd9e8e236705493d12a49 to your computer and use it in GitHub Desktop.
How to add common libraries into Android modules by defining them in root gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.feature' | |
apply plugin: 'kotlin-android' | |
android { | |
compileSdkVersion 28 | |
baseFeature true | |
defaultConfig { | |
minSdkVersion 19 | |
targetSdkVersion 28 | |
versionCode 1 | |
versionName "1.0" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
} | |
dependencies { | |
api "androidx.appcompat:appcompat:$app_compact_version" | |
api "com.google.android.gms:play-services-auth:$play_service_version" | |
commonDependencies.each { key, value -> | |
if (key.endsWith('Anno')) { | |
annotationProcessor value | |
} else if (key.endsWith('Impl')) { | |
implementation value | |
} else if (key.endsWith('Api')) { | |
api value | |
} | |
} | |
application project(':app') | |
feature project(':instant') | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Top-level build file where you can add configuration options common to all sub-projects/modules. | |
buildscript { | |
repositories { | |
google() | |
jcenter() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:3.2.1' | |
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | |
// NOTE: Do not place your application dependencies here; they belong | |
// in the individual module build.gradle files | |
} | |
} | |
allprojects { | |
repositories { | |
google() | |
jcenter() | |
} | |
} | |
ext { | |
commonDependencies = [ | |
// Layout Libraries | |
constraintLayoutApi : "androidx.constraintlayout:constraintlayout:$constraintlayout_version", | |
materialApi : "com.google.android.material:material:$material_version", | |
flexboxApi : "com.google.android:flexbox:$flexbox_version", | |
// Image library (Picasso is alternative) | |
glideImpl : "com.github.bumptech.glide:glide:$glide_version", | |
glideCompilerAnno : "com.github.bumptech.glide:compiler:$glide_version", | |
// Network library (Volley is alternative) | |
retrofitImpl : "com.squareup.retrofit2:retrofit:$retrofit_version", | |
retrofitJacksonImpl : "com.squareup.retrofit2:converter-jackson:$retrofit_version", | |
retrofitScalarsImpl : "com.squareup.retrofit2:converter-scalars:$retrofit_version", | |
retrofitJava8Impl : "com.squareup.retrofit2:converter-java8:$retrofit_version", | |
// Dependency Injection | |
daggerImpl : "com.google.dagger:dagger:$dagger_version", | |
daggerCompilerAnno : "com.google.dagger:dagger-compiler:$dagger_version", | |
// we add this so we can use the android support libraries | |
daggerAndroidSupportImpl: "com.google.dagger:dagger-android-support:$dagger_version", | |
daggerProcessorAnno : "com.google.dagger:dagger-android-processor:$dagger_version" | |
] | |
} | |
task clean(type: Delete) { | |
delete rootProject.buildDir | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kotlin_version=1.3.11 | |
app_compact_version=1.0.2 | |
constraintlayout_version=1.1.3 | |
material_version=1.1.0-alpha01 | |
flexbox_version=1.1.0 | |
play_service_version=16.0.1 | |
glide_version=4.8.0 | |
retrofit_version=2.5.0 | |
dagger_version=2.19 | |
# 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 | |
# Specifies the JVM arguments used for the daemon process. | |
# The setting is particularly useful for tweaking memory settings. | |
org.gradle.jvmargs=-Xmx1536m | |
# 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 | |
# Kotlin code style for this project: "official" or "obsolete": | |
kotlin.code.style=official | |
android.useAndroidX=true | |
android.enableJetifier=true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment