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

[KSP] dagger-android unresolved generated subcomponent for internal module methods used across gradle modules #4197

Open
wbonnefond opened this issue Dec 20, 2023 · 3 comments

Comments

@wbonnefond
Copy link

Opening up this ticket to track after discussion in #4193

With dagger-android KSP support in 2.49, referencing a dagger Module which has an internal @ContributesAndroidInjector method in a @ContributesAndroidInjector(modules = []) annotation in different gradle module will cause the build to fail because it cannot resolve a generated subcomponent class. This setup works using KAPT.

e: [ksp] ComponentProcessingStep was unable to process 'com.example.daggerandroid.ExampleModule_ContributeAppClass$app_debug.AppClassSubcomponent' because '<error>' could not be resolved.

Dependency trace:
    => element (CLASS): com.example.mylibrary.LibraryModule_ContributeLibraryClass$mylibrary_debug
    => annotation type: dagger.Module
    => annotation: @dagger.Module(includes={}, subcomponents={<error>})
    => annotation value (TYPE_ARRAY): subcomponents={<error>}
    => annotation value (TYPE): subcomponents=<error>

If type '<error>' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type '<error>' is on your classpath.
e: Error occurred in KSP, check log for detail

I have added a reproducer project here: https://github.com/wbonnefond/DaggerAndroidKspError

In the previous discussion @bcorso had said:

The latest issue your seeing seems to be a bug in KSP (or XProcessing) where it doesn't seem to be able to handle class names that contain $ when referenced from annotations. In this case it affects the class Dagger generates from the @ContributesAndroidInjector annotation:

@Generated
@Module(subcomponents = LibraryModule_ContributeLibraryClass$mylibrary_debug.LibraryClassSubcomponent.class)
public abstract class LibraryModule_ContributeLibraryClass$mylibrary_debug {
 ...
}

In particular, the LibraryModule_ContributeLibraryClass$mylibrary_debug.LibraryClassSubcomponent type within the annotation is showing up as error type, hence the error message you're seeing.

@wbonnefond wbonnefond changed the title [KSP] dagger-android unresolved generate subcomponent for internal methods used across modules [KSP] dagger-android unresolved generated subcomponent for internal module methods used across gradle modules Dec 21, 2023
@bcorso
Copy link

bcorso commented Dec 28, 2023

I was able to reproduce this and show that it's an issue in KSP that's not specific to Dagger.

I've filed google/ksp#1671.

@wbonnefond
Copy link
Author

@bcorso looks like this was fixed in the latest version of KSP (1.9.22-1.0.17). Any chance this can be pulled into the next release? It would require updating the kotlin version

@bcorso
Copy link

bcorso commented Jan 23, 2024

Hi @wbonnefond I think you should be able to just upgrade that dependency yourself in your own app (i.e. you control the Kotlin and KSP version). If that doesn't work for you let us know (along with any details why it didn't work).

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

2 participants