?? Simplify Your Gradle Dependencies with Version Catalogs! ??
Krishna Kumar
SDE - 2 Mobile @ Classplus. | Android development - (Kotlin/Java, Jetpack compose, Clean Architecture, Coroutine, Flow, Hilt) | IOS development - (Swift/ObjC, UIKit, SwiftUi, Clean Architecture)
Hey Android Developers! ??
I'm excited to share a powerful new feature in Gradle that will make managing dependencies in your Android projects easier than ever: Version Catalogs.
What Are Version Catalogs?
Version Catalogs allow you to centralize and streamline your dependency and plugin management. Instead of scattering dependency versions across multiple build files, you can now define them in a single libs.versions.toml file. This makes your project more maintainable and less error-prone.
How to Use Version Catalogs
# in settings.gradle file:
enableFeaturePreview("VERSION_CATALOGS")
# gradle/libs.versions.toml
[versions]
kotlin = "1.8.0"
coroutines = "1.6.4"
hilt = "2.45"
agp = "8.0.0"
[libraries]
kotlinStdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
coroutinesCore = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }
hiltAndroid = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
hiltCompiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt" }
[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
hilt = { id = "dagger.hilt.android.plugin", version.ref = "hilt" }
kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
# In build.gradle file (Module level)
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.hilt)
alias(libs.plugins.kapt)
}
android {
compileSdk = 33
defaultConfig {
applicationId = "com.example.myapp"
minSdk = 21
targetSdk = 33
versionCode = 1
versionName = "1.0"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
}
dependencies {
implementation(libs.kotlinStdlib)
implementation(libs.coroutinesCore)
implementation(libs.hiltAndroid)
kapt(libs.hiltCompiler)
}
Benefits of Version Catalogs
Getting Started
To start using version catalogs, simply update your Gradle to the latest version and follow the steps above. It's a small change that can have a big impact on your project's maintainability and your team's productivity.
Let's embrace these features and continue building amazing Android apps! ??
Feel free to reach out if you have any questions or need further clarification.
Happy Coding! ????????
#AndroidDevelopment #Gradle #Kotlin #MobileDevelopment #Programming #SoftwareEngineering #TechUpdates