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][Android] Non existing type error on class generated from Android Navigation arguments #4061

Open
cemore2048 opened this issue Sep 7, 2023 · 4 comments

Comments

@cemore2048
Copy link

The "non existing" type here is a class that's generated by the navigation library. It used to be picked up with Hilt using Kapt.
I've tried looking for any extra setup that I might be missing, but I might have overlooked something.

e: [ksp] AssistedInjectProcessingStep was unable to process 'HallwayTabViewModel(com.clubhouse.android.ui.hallway.HallwayTabViewState,com.clubhouse.session.di.SessionComponentHandler,com.clubhouse.android.shared.auth.UserManager,com.clubhouse.android.error.ErrorMessageFactory)' because 'error.NonExistentClass' could not be resolved.

Dependency trace:
    => element (CLASS): com.clubhouse.android.ui.hallway.HallwayTabViewModel
    => element (METHOD): handleDeeplinkArguments(error.NonExistentClass)
    => element (PARAMETER): args
    => type (ERROR parameter type): error.NonExistentClass

If type 'error.NonExistentClass' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type 'error.NonExistentClass' is on your classpath.

The param is using an assisted inject here

data class HallwayTabViewState(
    internal val args: MainTabFragmentArgs,
    ...
) : MavericksState {

    constructor(arguments: Bundle) : this(
        args = MainTabFragmentArgs.fromBundle(arguments),
    )
}


class HallwayTabViewModel @AssistedInject constructor(
    @Assisted initialState: HallwayTabViewState
    ....
) {

    init {
        handleDeeplinkArguments(initialState.args) <-- the `MainTabFragmentArgs`
    }
}
@danysantiago
Copy link
Member

The root cause of this is similar to the one regarding ViewBinding generated classes (#4051) or the AGP BuildConfig generated class (#4049), which is that the Navigation Safe Args plugins is generating classes that are not being wired as inputs for KSP hence Dagger is unable to resolve them.

@ispam
Copy link

ispam commented Oct 26, 2023

In case anyone needs the variant on Kotlin DSL ->

 androidComponents {
        onVariants(selector().all()) { variant ->
            afterEvaluate {
                // This is a workaround for https://issuetracker.google.com/301245705 which depends on internal
                // implementations of the android gradle plugin and the ksp gradle plugin which might change in the future
                // in an unpredictable way.
                val dataBindingTask = this.project.tasks.named ("dataBindingGenBaseClasses" + variant.name.capitalize()).get() as com.android.build.gradle.internal.tasks.databinding.DataBindingGenBaseClassesTask

                if (dataBindingTask != null) {
                    project.tasks.getByName("ksp" + variant.name.capitalize() + "Kotlin") {
                        (this as org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompileTool<*>).setSource(dataBindingTask.sourceOutFolder)
                    }
                }
            }
        }
    }

@ansman
Copy link

ansman commented Jan 6, 2024

@danysantiago I'm confused why it's being shown as error.NonExistentClass though, I though that was a KAPT thing?

@bcorso
Copy link

bcorso commented Jan 6, 2024

Dagger uses XProcessing, which uses error.NonExistentClass for consistency if there's a type it can't resolve:

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KSTypeJavaPoetExt.kt;l=39-42

Note: I think this is mostly needed because KSP is currently missing information in their error types so that we can't even get the simple name of the type used in the code (google/ksp#1232). Once that bug is fixed, I imagine we would start reporting that rather than the generic error.NonExistentClass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants