안드로이드/안드로이드 프레임워크

Dagger

냥냥냥냥냥냥 2022. 4. 13. 21:57

안드로이드 개발자들이 왜 Dagger에 관심을 가지고, 또 Dagger를 개발 모듈에 적용하고 싶어 하는지 하나씩 알아보고자 한다

 

 

 

 

 

Trouble Shooting


 

// appComponent lives in the Application class to share its lifecycle
class MyApplication : Application() {
    // Reference to the application graph that is used across the whole app
    var appComponent: ApplicationComponent = DaggerApplicationComponent.create()

}

Unresolved reference: DaggerApplicationComponent

 

위와 같은 에러가 발생한다면 먼저 build.gradle에 아래와 같이 추가를 부탁드립니다

(Dagger 버전은 원하시는 버전 쓰셔도 무방합니다)

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'  // Need to add this for using dagger
}
dependencies {
    implementation 'com.google.dagger:dagger:2.12'   // Need to add this for using dagger
    kapt "com.google.dagger:dagger-compiler:2.12"    // Need to add this for using dagger

그 후 Rebuild Project 한 번 해주시면 됩니다

 

 

 

 

 

 

Test app Git Hub 주소


https://github.com/kdh0503/DaggerTest/