我在 BottomSheetDialogFragmet() 中使用 ViewModel,所以我必须用 @AndroidEntryPoint 标记我的 BottomSheet。
\n@AndroidEntryPoint\nclass SearchAddressDialog : BottomSheetDialogFragment() {\n\n private val viewModel: MyAddressesViewModel by viewModels()\n \n ......\n}\nRun Code Online (Sandbox Code Playgroud)\n但是当我尝试构建我的项目时,它给了我这个错误:
\nExecution failed for task \':app:kaptDebugKotlin\'.\n> A failure occurred while executing \norg.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction\n> java.lang.reflect.InvocationTargetException (no error message)\n\n* Try:\nRun with --stacktrace option to get the stack trace. Run with --info or --debug option \nto get more log output. Run with --scan to get full insights.\nRun Code Online (Sandbox Code Playgroud)\n这是我使用 --stacktrace 运行的输出
\nhttps://gist.github.com/javlonrahimov/95de968645cace1dfb6e425381f8014b
\n如果我删除 BottomSheetFragmen() 上方的 @AndroidEntryPoint,它将构建并安装应用程序。但是当我尝试打开 BottomSheet 时,当我将存储库注入 …
我在项目中添加 hilt 依赖项时遇到问题
插件
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'realm-android'
id 'androidx.navigation.safeargs.kotlin'
id 'kotlin-parcelize'
}
Run Code Online (Sandbox Code Playgroud)
依赖关系
//Dependency injection with Hilt
implementation("com.google.dagger:hilt-android:2.38.1")
kapt("com.google.dagger:hilt-android-compiler:2.38.1")
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
Run Code Online (Sandbox Code Playgroud)
build.gradle 项目级别
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath "io.realm:realm-gradle-plugin:10.11.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' …Run Code Online (Sandbox Code Playgroud)