새소식

Android/[Android] ETC

[Android Clean Architecture] Hilt 설정

  • -
1. Version Catalog 세팅 기준으로 했습니다.
2. app, data, domain, presentation 모듈이 생성되어 있는 기준입니다. 

 

Version Catalog (libs.versions.toml)

[versions]
...
...

kotlin = "2.0.0"

...
...

#Hilt
hilt = "2.51.1"
androidx-hilt = "1.2.0"
#Kapt
kapt = "1.8.10"
#Ksp
ksp = "2.0.0-1.0.21"


[libraries]
...
...

#Hilt
hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
hilt-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt"}
androidx-hilt-complier = { group = "androidx.hilt", name = "hilt-compiler", version.ref = "androidx-hilt" }
androidx-hilt-navigation = {group = "androidx.hilt", name = "hilt-navigation-fragment", version.ref = "androidx-hilt"}

[plugins]
...
...
android-library = { id = "com.android.library", version.ref = "agp" }
hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }

 

build.gradle.kts (project)

plugins {
	...
    ...
    alias(libs.plugins.hilt.android) apply false
    alias(libs.plugins.ksp) apply false
}

 

 

 

build.gradle.kts (Module: app)

plugins {
    ...
    alias(libs.plugins.hilt.android)
    alias(libs.plugins.ksp)
}

dependencies {
    implementation(project(":presentation"))
    implementation(project(":data"))
    implementation(project(":domain"))

	...
    ...

    // Hilt
    implementation(libs.hilt.android)
    ksp(libs.hilt.compiler)
    ksp(libs.androidx.hilt.complier)
    implementation(libs.androidx.hilt.navigation)
}

 

 

 

build.gradle.kts (Module: data)

plugins {
    ...
    alias(libs.plugins.hilt.android)
    alias(libs.plugins.ksp)
}

dependencies {
    implementation(project(":domain"))

	...

    // Hilt
    implementation(libs.hilt.android)
    ksp(libs.hilt.compiler)
}

 

 

 

build.gradle.kts (Module: presentation)

plugins {
    ...
    alias(libs.plugins.hilt.android)
    alias(libs.plugins.ksp)
}


dependencies {
    implementation(project(":domain"))

    ...
    ...

    // Hilt
    implementation(libs.hilt.android)
    ksp(libs.hilt.compiler)
    ksp(libs.androidx.hilt.complier)
    implementation(libs.androidx.hilt.navigation)
}

 

 

 

 

[참고]

1: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:kspDebugKotlin'.
   > Could not create task of type 'KspTaskJvm'.
      > Could not generate a decorated class for type KspTaskJvm.
         > Type org.jetbrains.kotlin.buildtools.api.SourcesChanges not present

위 에러가 발생했었습니다.
kotlin 버전과 ksp 버전 싱크가 맞지 않아서 발생한 문제로 판단됩니다. 
해결: ksp 버전 "2.0.0-1.0.21"과 Kotlin 2.0.0을 사용해서 해결 했습니다.
https://github.com/google/ksp/releases

 

Releases · google/ksp

Kotlin Symbol Processing API. Contribute to google/ksp development by creating an account on GitHub.

github.com

 

 

여기까지 진행하셨으면 빌드가 성공적으로 될 것입니다. 

 

 

 

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.