4

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?

Villa
  • 429
  • 5
  • 17
  • (Sorry for the edit noise, I thought this was purely for Dagger 1, but after reading a bit more on the library it looks like it applies to Dagger 2. Since the InflationInject library seems to be a separate annotation processor, it may help if you could show us your Gradle file to make sure you've included the code generator that would generate that version of the module. Thanks!) – Jeff Bowman Nov 15 '18 at 18:33
  • Hi, yes this is for Dagger 2. I've added my `build.gradle` (the relevant bits) above. – Villa Nov 16 '18 at 10:38

1 Answers1

3

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.

Tuấn Kiệt
  • 292
  • 3
  • 13
  • 1
    Thanks. By commenting AssistedInjectionModule out of my AppComponent I was able to see the *real* error that was preventing build. – Tom Mar 31 '20 at 21:53