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

3.1k views Asked by At

I've tried implementing Jake Wharton's AssistedInject with Dagger 2 (https://github.com/square/AssistedInject) in my project.

My code is pretty much identical to https://github.com/square/AssistedInject/tree/master/inflation-inject-sample/src/main/java/com/example but I get the error:

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

It seems like ViewModule generated code doesn't know where to find InflationInject_ViewModule:

@InflationModule
@Module(includes = [InflationInject_ViewModule::class])
abstract class ViewModule

The relevant bits of my build.gradle are

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'
}

I have checked that InflationInject_ViewModule does exist in generated code (at build/generated/source/kapt/devDebug/com/project/di/, so maybe it's something to do with where the compiler looks for source sets / generated code.

Any suggestions?

1

There are 1 answers

1
Tuấn Kiệt On

I use AssistedInject, facing the same problem. In my case, turn out there is nothing wrong with my (or your) code, it's kapt problem.

If you use some library that requires kapt (e.g. room, databinding) those libraries may process before AssistedInject.
Something like: databinding -> room -> AssistedInject
If room compile fail, AssistedInject is never compile therefor InflationInject_ViewModule.java is not generated

Example error:

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> {
                ^


Conclution: check out other libraries in your project that require annotation processor. Make sure their setup was correct.