Skip to content

[KSP2] Generated provider code failure when providing internal types for android library modules #4493

@mcumings

Description

@mcumings

Preconditions:

  • Using Dagger 2.52
  • Using KSP 2.0.21-1.0.26
  • Using the org.jetbrains.kotlin.android and com.android.library gradle plugins (this works with standard kotlin + org.jetbrains.kotlin.jvm)

Provided an internal type:

internal class InternalType(val value: String)

A class which leverages the internal type:

internal class InjectionReceiver @Inject constructor(val internalType: InternalType)

and a module which defines a provider for it:

@Module
object ReproModule {
    @Provides
    internal fun provideInternalType(): InternalType = InternalType("Hello, World!")
}

The result of this is a compilation failure due to the generated factory code:

ReproModule_ProvideInternalType$libFactory.java:36: error: cannot find symbol
    return Preconditions.checkNotNullFromProvides(ReproModule.INSTANCE.provideInternalType$lib());
                                                                      ^
  symbol:   method provideInternalType$lib()
  location: variable INSTANCE of type ReproModule

The actual generated code at the point where it fails looks like this:

  public static InternalType provideInternalType$lib() {
    return Preconditions.checkNotNullFromProvides(ReproModule.INSTANCE.provideInternalType$lib());
  }

Looking at the generated code, it appears as if the above should read as follows:

  public static InternalType provideInternalType$lib() {
    return Preconditions.checkNotNullFromProvides(ReproModule.INSTANCE.provideInternalType$lib_debug());
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions