gpt4 book ai didi

dagger-2 - 错误 : cannot find symbol @dagger. 模块(包括 = {InflationInject_ViewModule.class})

转载 作者:行者123 更新时间:2023-12-03 23:53:40 26 4
gpt4 key购买 nike

我试过实现 jack 沃顿的 AssistedInject在我的项目中使用 Dagger 2 ( https://github.com/square/AssistedInject )。

我的代码与 https://github.com/square/AssistedInject/tree/master/inflation-inject-sample/src/main/java/com/example 几乎相同但我得到了错误:

error: cannot find symbol @dagger.Module(includes = {InflationInject_ViewModule.class})



好像是 ViewModule生成的代码不知道在哪里找到 InflationInject_ViewModule :
@InflationModule
@Module(includes = [InflationInject_ViewModule::class])
abstract class ViewModule

我的 build.gradle 的相关位是
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {...}

dependencies {
implementation "com.google.dagger:dagger-android:2.16"
implementation "com.google.dagger:dagger-android-support:2.16"
kapt "com.google.dagger:dagger-compiler:2.16"
kapt "com.google.dagger:dagger-android-processor:2.16"
implementation 'com.squareup.inject:inflation-inject:0.3.0'
kapt 'com.squareup.inject:inflation-inject-processor:0.3.0'
}

我已经检查过 InflationInject_ViewModule确实存在于生成的代码中(在 build/generated/source/kapt/devDebug/com/project/di/ ,所以它可能与编译器查找源集/生成代码的位置有关。

有什么建议么?

最佳答案

我使用 AssistedInject,面临同样的问题。就我而言,结果证明我(或您的)代码没有问题,这是 kapt 问题。

如果您使用一些需要 kapt 的库(例如房间、数据绑定(bind)),这些库可能会在 AssistedInject 之前处理。就像是:
数据绑定(bind) -> 房间 -> AssistedInject
如果房间编译失败,AssistedInject 永远不会为此编译 InflationInject_ViewModule.java 没有生成

示例错误:

e: AssistedInjectModule.java:7: error: cannot find symbol
@dagger.Module(includes = {AssistedInject_AssistedInjectModule.class})
^
symbol: class AssistedInject_AssistedInjectModule
e: error: Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
Tried the following constructors but they failed to match:
Integer(int) -> [param:value -> matched field:unmatched]
Integer(java.lang.String) -> [param:arg0 -> matched field:unmatched] - java.lang.Integer
e: error: Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type). - java.lang.Integer
e: TaskDao.java:53: error: Not sure how to convert a Cursor to this method's return type (java.lang.Integer).
public abstract java.lang.Object updateComplete(@org.jetbrains.annotations.NotNull()
^
e: AssistedInjectModule.java:8: error: @AssistedModule's @Module must include AssistedInject_AssistedInjectModule
public final class AssistedInjectModule {
^
e: AppComponent.java:8: error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public abstract interface AppComponent extends dagger.android.AndroidInjector<com.sample.todo.TodoApplication> {
^

结论 :查看项目中需要注释处理器的其他库。确保他们的设置是正确的。

关于dagger-2 - 错误 : cannot find symbol @dagger. 模块(包括 = {InflationInject_ViewModule.class}),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53322693/

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