์๋๋ก์ด๋ ํ๋ก์ ํธ์ Hilt๋ฅผ ์ค์ ํ ๋๋
ํ๋๋ง ๋น ์ ธ๋ ๋น๋๊ฐ ์๋๋ ์๋ฌ๊ฐ ๋ฐ์ํ๊ธฐ ๋๋ฌธ์ ๋น ์ง ๊ฒ ์๋ ์ง ์ฃผ์ํด์ผ ํฉ๋๋ค.
์ ๋ชฉ๊ณผ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ์ ๋๋
gradle์ ๋น ๋จ๋ฆฐ ๊ฒ ์๋์ง ํ์ธํด์ผ ํ๋๋ฐ
์ฐ์ app ์์ค์ build.gradle ์๋ ์๋์ ๊ฐ์ ๋ด์ฉ๋ค์ด ๋ค์ด๊ฐ ์์ด์ผ ํฉ๋๋ค.
plugins {
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
dependencies {
implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-android-compiler:2.44"
}
๊ทธ๋ฆฌ๊ณ project ์์ค์ build.gradle ์๋ ์๋์ ๊ฐ์ ๋ด์ฉ๋ค์ด ๋ค์ด๊ฐ ์์ด์ผ ํฉ๋๋ค.
plugins {
id 'com.google.dagger.hilt.android' version '2.44' apply false
}
hilt์ ์ต์ ๋ฒ์ ์ ๊ณต์ ๋ฌธ์์์ ํ์ธํ ์ ์์ต๋๋ค.
https://developer.android.com/training/dependency-injection/hilt-android?hl=ko
์ ๊ฐ ํด๋น ์๋ฌ๊ฐ ๋ฐ์ํ๋ ์ด์ ๋ plugins์ ๊ธฐ์ ์ ๋น ๋จ๋ ธ๊ธฐ ๋๋ฌธ์ด์๊ตฌ์ ๐คง
๋ค๋ฅธ ๋ถ๋ค์ ์์ ์ ๋ณด๋ฉด
1. ์ด๋ ธํ ์ด์ ํ๋ก์ธ์ ์ธ์๋ฅผ ์ฌ์ ์ ์ด์
javaCompileOptions {
annotationProcessorOptions {
arguments += ["foo" : "bar"]
}
}
(+ ๋ฅผ ๋ถ์ด์ง ์๊ณ ์ฌ์ ์๋ฅผ ํ๋ค๋ฉด ์ปดํ์ผ ์คํจํ๋ค๊ณ ํจ)
2. kotlin 1.5.20 kapt ์ด์ฉํ์ ๋์ ๋ฒ์ ์ด์
kapt {
javacOptions {
option("-Adagger.fastInit=ENABLED")
option("-Adagger.hilt.android.internal.disableAndroidSuperclassValidation=true")
}
}
(ํด๋น ๋ฒ์ ์ ๋ฎ์ถ๊ฑฐ๋ ๋์ด๊ฑฐ๋ annotation ์ค์ ํด์ผ ํ๋ค๊ณ ํจ)
3. implementation / kapt ํ๋ hilt version ์์ด ์ด์
(gradle์ ๊ธฐ์ ํ hilt๋ค์ version์ ๋ชจ๋ ๋์ผํ๊ฒ ๋ง์ถฐ์ค์ผ ํจ)
๋ฑ์ ์ด์ ๋ค๋ ์์์ต๋๋ค.
hilt๋ฅผ ์ค์ ํ๋ค๋ฉด ์ ๋ง ๋ฒ์ ํ๋ํ๋ ๋ฏ์ด๋ด์ผ ํ ๊ฒ ๊ฐ์ต๋๋ค.. ๐ฅฒ
( ์ฐธ๊ณ )
https://whyprogrammer.tistory.com/641
https://www.charlezz.com/?p=44320