gpt4 book ai didi

android - 尝试使用 Dagger 刀柄的代码时出现此错误,错误 :[Hilt] java. lang.reflect.InvocationTargetException(无错误消息)

转载 作者:行者123 更新时间:2023-12-04 23:56:07 24 4
gpt4 key购买 nike

我尝试使用 API 在原生 Android 中制作货币转换器的代码。我使用了 Retrofit、Dagger-Hilt 和 MVVM 架构设计模式。完成所有编码后,这是我得到的错误。 API 获取实时货币汇率,从 json 转换为 kotlin 并使用。
Gradle 文件
这是我添加了所有依赖项的 gradle 文件。

plugins {

id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}

android {
compileSdkVersion 29

defaultConfig {
applicationId "com.example.currency"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

buildTypes {

release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}


compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}

buildFeatures{
viewBinding true
dataBinding true
}

}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.3.0-beta01'
implementation 'androidx.appcompat:appcompat:1.3.0-beta01'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'

//dagger - hilt
implementation "com.google.dagger:hilt-android:2.31-alpha"
kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0-beta01"

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

//Architectural components
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0"

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

//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'

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

//Coroutines Lifecycle Scopes
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.0"
}

最佳答案

就像我在评论和我的 github PR 中提到的那样。解决方法是使用同版本的hilt-android,编译器

关于android - 尝试使用 Dagger 刀柄的代码时出现此错误,错误 :[Hilt] java. lang.reflect.InvocationTargetException(无错误消息),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66643734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com