How to add Hilt dependencies on "libs.versions.toml" file in android studio
Asked Answered
S

1

10

I am using Android Studio Iguana | 2023.2.1 Patch 1. Create sample project it default configured build.gradle.kts(app) in this gradle "libs.versions.toml" file created,

Now i add hilt on toml file after that, the file not showing in build.gradle. Attached screenshot please guide me to solve this build issue.

implementation(libs.hilt) showing error

enter image description here

Shirring answered 15/4 at 7:29 Comment(2)
Please don't post config file data as screenhsotSandbox
okay @Sandbox this is simple sample test file only, so that I shared it.Shirring
A
27

Hilt dependency in toml file with KSP

Add Hilt and KSP in toml file

 [libraries]
 hilt-android = { group = "com.google.dagger", name = "hilt-android" , 
                version.ref = "hiltVersion"}
 hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler" , 
                version.ref = "hiltVersion"}

 
 [plugins]
 kotlinAndroidKsp = { id = "com.google.devtools.ksp", version.ref = 
                "kspVersion" }
 hiltAndroid = { id = "com.google.dagger.hilt.android", version.ref = 
                "hiltVersion" }

Add Plugin In Project build.gradle.kts

 alias(libs.plugins.hiltAndroid) apply false
 alias(libs.plugins.kotlinAndroidKsp) apply false

Add Plugin in app build.gradle.kts

 alias(libs.plugins.kotlinAndroidKsp)
 alias(libs.plugins.hiltAndroid)

Add hilt dependency in app build.gradle.kts

 implementation(libs.hilt.android)
 ksp(libs.hilt.compiler)

Now Sync gradle build and error will resolved

Happy coding :)

Altigraph answered 15/4 at 13:42 Comment(5)
Thank you, It was working good expect ksp(libs.hilt.compiler). I changed to implementation(libs.hilt.compiler) after build successfully.Shirring
KSP is new compiler, previously i have used KeptAltigraph
Hi @Altigraph nav_version = "2.7.7" androidx-navigation-compose = { group = "androidx.navigation:navigation-compose", name= "nav_version" } how to add it on build.gradle(app) like implementation(libs.androidx.) I am not found any good resource so every time i struck with this please help me.Shirring
navigationComposeVersion="2.7.1". [libraries] navigation-compose = { group = "androidx.navigation", name = "navigation-compose" , version.ref = "navigationComposeVersion"} In app build gradle implementation(libs.navigation.compose) Rebuild the project, that will work Please read the blog post linkedin.com/pulse/…Altigraph
The blog post was very useful, Thank you..! @AltigraphShirring

© 2022 - 2024 — McMap. All rights reserved.