android Kotlin+ hilt错误,[Hilt]和java.lang.reflect.InvocationTargetException(无错误消息)

eiee3dmh  于 2023-05-12  发布在  Android
关注(0)|答案(7)|浏览(159)

我的刀柄注射有问题。最近我开始为我的项目学习Kotlin和Hilt。我看了一些教程,然后试着自己写代码
我的身材gradle

dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.dagger:hilt-android-gradle-plugin:2.28.3-alpha"
        classpath 'com.google.gms:google-services:4.3.8'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

    }
}

allprojects {
    repositories {
        google()
        mavenCentral()

    }
}

还有这个,gradle

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            debuggable true
            signingConfig signingConfigs.config
        }
        debug {
            signingConfig signingConfigs.config
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'com.google.firebase:firebase-firestore:23.0.0'
    implementation 'com.google.firebase:firebase-storage:20.0.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation platform('com.google.firebase:firebase-bom:28.0.1')
    implementation 'com.google.firebase:firebase-analytics'

    implementation 'com.google.android.exoplayer:exoplayer:2.14.0'
    implementation 'com.google.android.exoplayer:exoplayer-core:2.14.0'
    implementation 'com.google.android.exoplayer:exoplayer-dash:2.14.0'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.14.0'

    // Material Design
    implementation 'com.google.android.material:material:1.3.0-alpha02'

    // Architectural Components
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"

    // Lifecycle
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
    implementation "androidx.lifecycle:lifecycle-runtime:2.2.0"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"

    // Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'

    // Coroutine Lifecycle Scopes
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"

    // Navigation Component
    implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
    implementation "androidx.navigation:navigation-ui-ktx:2.3.0"

    // Glide
    implementation 'com.github.bumptech.glide:glide:4.11.0'

    // Activity KTX for viewModels()
    implementation "androidx.activity:activity-ktx:1.1.0"

    //Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.28-alpha"
kapt 'com.google.dagger:hilt-android-compiler:2.28-alpha'
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02"
kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha02'

}

我有一个java.lang.reflect.InvocationTargetException (no error message)错误,控制台中只有一条消息This one message
怎么了?我看了很多建议,但没有一个有帮助
Injection code

fykwrbwg

fykwrbwg1#

你是否将 hilt-android-gradle-plugin 添加到项目的根build.gradle文件中?我的gradle看起来是这样的:

plugins {
   id 'com.android.application'
   id 'kotlin-android'
   id 'kotlin-kapt'
   id 'dagger.hilt.android.plugin'
   id 'kotlin-parcelize'
}
mbjcgjjk

mbjcgjjk2#

只要加上这个

hilt {
    enableAggregatingTask = true
}

到你的build.gradle模块中

dependencies {
    implementation project(path: ":core")
    implementation project(path: ":domain")
    implementation project(path: ":features:homepage")
    implementation project(path: ":features:detailpage")
}

hilt {
    enableAggregatingTask = true
}
bqf10yzr

bqf10yzr3#

我只是改变了我的依赖的classpath版本一样,我的剑柄版本在

buld.gradle文件(项目级)

像这样

dependencies {classpath("com.google.dagger:hilt-android-gradle-plugin:2.38.1")}

rm5edbpk

rm5edbpk4#

您的classpath版本应该与这两个相同

implementation "com.google.dagger:hilt-android:2.28-alpha"
kapt 'com.google.dagger:hilt-android-compiler:2.28-alpha'

如果还是不行。尝试更新所有与最新版本相关的刀柄,并确保将kotlin_version更改为1.4.32。如果你想看到的变化柄检查出这一点:https://github.com/google/dagger/releases

watbbzwu

watbbzwu5#

我也遇到了同样的问题,并通过将Dagger Hilt依赖项更新到最新版本来解决。您可以在documentation中找到最新版本

d4so4syb

d4so4syb6#

我使用了'1.5.30'而不是'1.7.0',它工作了
ID 'org.jetbrains.kotlin.android'版本'1.5.30'应用错误

bxjv4tth

bxjv4tth7#

你的职业路径手柄版本和你的手柄版本不一样。
build.gradle(:app)

id 'com.google.dagger.hilt.android' version '2.44' apply false

build.gradle(模块)

def hilt_version="2.44"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"

相关问题