Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LazyClassKey not supported when using Dagger 2.53 #1079

Open
bddckr opened this issue Dec 6, 2024 · 1 comment
Open

LazyClassKey not supported when using Dagger 2.53 #1079

bddckr opened this issue Dec 6, 2024 · 1 comment

Comments

@bddckr
Copy link
Contributor

bddckr commented Dec 6, 2024

Using Anvil 2.5.0 with Dagger version 2.52 I have no issues. But updating Dagger to 2.53 (and doing no other changes to the project) gives issues when @LazyClassKey is used:

/something/build/generated/source/kapt/debugAndroidTest/something/DaggerSomethingComponent.java:41: error: cannot find symbol
import something.SomethingElse_Module_ProvideType_LazyMapKey;
                                       ^
  symbol:   class SomethingElse_Module_ProvideType_LazyMapKey

The SomethingElse_Module is generated by my own code generator via Anvil.

// Generated by Anvil.
// https://github.com/square/anvil
@file:Suppress(
  "DEPRECATION",
  "OPT_IN_USAGE",
  "OPT_IN_USAGE_ERROR",
)

package something

import com.squareup.anvil.annotations.ContributesTo
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
import dagger.multibindings.IntoSet
import dagger.multibindings.LazyClassKey
import dagger.multibindings.StringKey
import kotlin.String
import kotlin.Suppress
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.polymorphic
import kotlinx.serialization.modules.subclass

@Module
@ContributesTo(AppScope::class)
public object SomethingElse_Module {
  @Provides
  @IntoMap
  @LazyClassKey(SomethingElse::class)
  public fun provideType(): String =
      "SomethingElse"
}

Note that I had to rename/hide some sensitive details here. Hopefully it still makes sense.

I can work on a reproducer, if required. Didn't dig down into it just yet and wanted to open the issue in the meantime.

@bddckr
Copy link
Contributor Author

bddckr commented Jan 25, 2025

Just noting here that Anvil is probably missing generation of the new class for LazyClassKey:

This looks like an Anvil issue.

Anvil uses its own Kotlin plugin to generate factory classes for modules -- i.e. it attempts to replace Dagger's annotation processor and handle code generation itself. In Dagger 2.53 there's an additional generated class for LazyClassKey in modules, so I suspect the issue is that Anvil doesn't yet generate this class.

google/dagger#4530 (comment)

@bddckr bddckr changed the title Cannot find symbol _LazyMapKey in Dagger 2.53 LazyClassKey not supported when using Dagger 2.53 Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant