gpt4 book ai didi

android - 未找到 DefaultActivityViewModelFactory

转载 作者:行者123 更新时间:2023-12-04 04:31:51 28 4
gpt4 key购买 nike

2.33-beta 迁移 Hilt 版本后至2.35我的项目已停止构建,出现以下错误:
enter image description here
一个txt版本:

error: cannot access DefaultActivityViewModelFactory    
class file for dagger.hilt.android.internal.lifecycle.DefaultActivityViewModelFactory not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for dagger.hilt.android.internal.lifecycle.DefaultActivityViewModelFactory not found
我的 build.gradle (项目)的 fragment :
buildscript {
ext.hilt_version = '2.33-beta'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32"
...
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
}
}

allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
我的 build.gradle (应用程序)的 fragment :
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

android {
compileSdkVersion 29
...

defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments += [
"room.schemaLocation": "$projectDir/schemas".toString(),
"room.incremental" : "true"
]
}
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}

buildFeatures {
viewBinding true
dataBinding true
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
...

//DI
implementation "com.google.dagger:hilt-android:$hilt_version"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
implementation 'androidx.hilt:hilt-work:1.0.0-beta01'
kapt "com.google.dagger:hilt-compiler:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
kapt 'androidx.hilt:hilt-compiler:1.0.0-beta01'

// INSTRUMENTED TESTS
...
androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
kaptAndroidTest "com.google.dagger:hilt-android-compiler:$hilt_version"
androidTestImplementation "androidx.work:work-testing:2.5.0"

//KOTLIN
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.32"

//LIFECYCLE
implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'

// WORK MANAGER
implementation "androidx.work:work-runtime-ktx:2.5.0"
}
有没有人遇到这个错误并知道可能是什么解决方案?

最佳答案

删除对 hilt-lifecycle-viewmodel 的依赖会导致错误消失,因为新版本的 hilt 不再需要它。
只需从您的应用程序级别删除此行 build.gradle文件,如果你有的话。implementation 'androidx.hilt:hilt-lifecycle-viewmodel:x.x.x'

关于android - 未找到 DefaultActivityViewModelFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67256565/

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