0
1

AndroidでHiltをつかう

Last updated at Posted at 2021-08-19

Android Studioでの設定

過去記載の内容だとうまくいかないので修正

プロジェクトのbuild.gradle

pluginsを新規に追記

plugins {
    id 'com.google.dagger.hilt.android' version '2.48' apply false
}

app/build.gradle

plugins {
    ・・・
    id 'kotlin-kapt'
    id 'com.google.dagger.hilt.android'
}
・・・
dependencies {
         ・・・
    implementation "com.google.dagger:hilt-android:2.48"
    kapt "com.google.dagger:hilt-android-compiler:2.48"
}

以下は、古い記事。
基本的にはチュートリアルの通りなのだが、少し違っているのでとても迷う。
https://developer.android.com/training/dependency-injection/hilt-android
以下に設定すれば通る

build.gradle

dependencies {
        ・・・
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
    }

app/build.gradle

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
・・・
dependencies {
        ・・・
    implementation "com.google.dagger:hilt-android:2.38.1"
    kapt "com.google.dagger:hilt-android-compiler:2.38.1"
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1