1

I have an already working dagger implementation. My android Application class is the one which inits Dagger2 implementation.

However when I add a method that uses Activity argument, then I get the dagger error:

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.

I have tested different variations and it only throws the error when I use the Activity param:

class MyApplication: Application() {

    ...

    fun addingThisFunWorks()

    fun addingThisFunReturningSomethingWorks(): ReturnClass

    fun addingThisFunWithParameterWorks(value: Int)

    fun addingThisFunThrowsDaggerError(activity: Activity)

}

Is it because Activity class depends on the Application class and that becomes circular somehow?

htafoya
  • 18,261
  • 11
  • 80
  • 104
  • Custom classes you create must have a 'package' prefix. Is there? – Salih Can Oct 16 '21 at 02:01
  • @SalihCan are you talking about Dagger or simply kotlin? I don't place the top package declaration here because it seems irrelevant for the question. – htafoya Oct 18 '21 at 22:35
  • My answer was not irrelevant to your question. My comment to the answer in this link solved my similar problem. https://stackoverflow.com/a/68796142/13109852 and Solved 3 other people's problems besides me. – Salih Can Oct 18 '21 at 22:48

1 Answers1

1

The problem is that Activity and Fragment references inside this class somehow is interpreted as a circular reference.

To fix it I need to create an "Intermediate" manager which has the function I need.

for example:

class MyApplication: Application() {

    ...

    fun addingThisFunWorks()

    fun addingThisFunReturningSomethingWorks(): ReturnClass

    fun addingThisFunWithParameterWorks(value: Int)

    fun returnMyManager(): MyManager

}

And have:

class MyManager {
    fun addingThisFunThrowsDaggerError(activity: Activity)
}
htafoya
  • 18,261
  • 11
  • 80
  • 104