Android Utility belt โ€” Collection of dependencies for a greenfield project

ยท

3 min read

Starting an android project will bring in a new set of challenges ๐Ÿ‘€ aka adding tons of Gradle dependencies.

Even though you use these dependencies in almost all your applications, you can't just grab them from the previous project because it might be an outdated version. By the time you find the latest version and add it to the project, you'd lose half the energy. Coming to the point!!

โ€ฆ

In this post, I composed a list of dependencies that I use in most of my projects. They're at the latest version when I write it(Oct 2021). For convenience, hyperlinked the maven central page so that picking the latest version is just a click away.

I highly recommend using this template project for greenfield projects. From DI/logger to instrumentation test everything has been perfectly set up. Though, the network dependencies are not present in the template. So, look up below and add dependencies as you see fit.

โ€ฆ

Network

OkHttp3

implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.2"))
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")

or

implementation 'com.squareup.okhttp3:okhttp:4.9.2'
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.2'
testImplementation("com.squareup.okhttp3:mockwebserver:4.9.2")
implementation 'com.squareup.okhttp3:mockwebserver3:5.0.0-alpha.2'

๐Ÿ“Œokhttp-bom โ€ƒ ๐Ÿ“Œ logging-interceptor

๐Ÿ“Œ mockwebserver โ€ƒ ๐Ÿ“Œ mockwebserver3

โ€ฆ

Retrofit

implementation 'com.squareup.retrofit2:retrofit:2.9.0'

implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'

implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'

๐Ÿ“Œ retrofit โ€ƒ ๐Ÿ“Œconverter-gson

๐Ÿ“Œ converter-moshi โ€ƒ ๐Ÿ“Œ adapter-rxjava2

๐Ÿ“Œ adapter-rxjava3


Threading and dispatchers

Coroutines

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.2'

๐Ÿ“Œcoroutines-core โ€ƒ ๐Ÿ“Œ coroutines-android

๐Ÿ“Œ coroutines-test

โ€ฆ

RXJava

  implementation 'io.reactivex.rxjava3:rxjava:3.1.2'    
  implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'

๐Ÿ“Œ rxjava โ€ƒ ๐Ÿ“Œrxandroid


Serialization

Moshi

implementation 'com.squareup.moshi:moshi:1.12.0'
implementation 'com.squareup.moshi:moshi-kotlin-codegen:1.12.0'

๐Ÿ“Œ moshi โ€ƒ ๐Ÿ“Œmoshi-codegen

โ€ฆ

GSON

implementation 'com.google.code.gson:gson:2.8.8'

๐Ÿ“Œ gson


Jetpack

Following dependencies are also available in Google maven.

Livedata / viewmodel

implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'

๐Ÿ“Œ viewmodel-ktxโ€ƒ ๐Ÿ“Œ livedata-ktx

โ€ฆ

UI

implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.recyclerview:recyclerview:1.2.0'

๐Ÿ“Œ material โ€ƒ ๐Ÿ“Œconstraintlayout

๐Ÿ“Œ recyclerview

โ€ฆ

Fragment

implementation 'androidx.fragment:fragment-ktx:1.3.6'

๐Ÿ“Œ fragment-ktx

โ€ฆ

implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'


androidTestImplementation 'androidx.navigation:navigation-testing:2.3.5'

๐Ÿ“Œ navigation-fragment-ktx โ€ƒ ๐Ÿ“Œnavigation-ui-ktx

๐Ÿ“Œ navigation-testing

โ€ฆ

Room - DB

 def room_version = "2.3.0"

implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
 // optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
// optional - Test helpers
testImplementation "androidx.room:room-testing:$room_version"

๐Ÿ“Œ room-ktx


Dependency injection

Dagger

Guide: developer.android.com/training/dependency-i..

// app level Gradle
apply plugin: 'kotlin-kapt'


{
    implementation 'com.google.dagger:dagger:2.39.1'
  kapt 'com.google.dagger:dagger-compiler:2.39.1'
}

๐Ÿ“Œ dagger

โ€ฆ

Hilt

Guide: developer.android.com/training/dependency-i..

// project level gradle
buildscript {
    dependencies {
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.39.1'
    }
}

// app level gradle
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

dependencies {
    implementation "com.google.dagger:hilt-android:2.39.1"
    kapt "com.google.dagger:hilt-compiler:2.39.1"

    implementation 'com.google.dagger:hilt-android-testing:2.39.1'
}

๐Ÿ“Œ hilt-android โ€ƒ ๐Ÿ“Œhilt-android-testing


Image loaders

Glide

implementation 'com.github.bumptech.glide:glide:4.12.0'

๐Ÿ“Œ glide

โ€ฆ

Coil

implementation 'io.coil-kt:coil:1.4.0'

๐Ÿ“Œ coil


Testing

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

testImplementation 'com.google.truth:truth:1.1.3'

๐Ÿ“Œ Google truth

ย