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: InjectProcessingStep was unable to process 'glide' because 'error.NonExistentClass' could not be resolved. #4174

Closed
ArcherEmiya05 opened this issue Dec 2, 2023 · 6 comments

Comments

@ArcherEmiya05
Copy link

ArcherEmiya05 commented Dec 2, 2023

Hi, just trying to migrate from KAPT to KSP since KSP for dagger-android became available in 2.49. Unfortunately I am having issue building the project with this setup. To summarize this is the setup looks like since I am not sure if KSP is having issue working with modularized structure or it is Glide issue.

Module: app

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.android.kotlin) // This should be put before any Kotlin dependent plugin
    alias(libs.plugins.ksp)
    id(libs.plugins.parcelize.get().pluginId)
}
dependencies {

    // Moshi
    ksp(libs.moshi.kotlin.codegen)

    // Room
    ksp(libs.room.compiler)

    // Dagger 2
    ksp(libs.dagger.compiler)
    ksp(libs.dagger.android.processor)

    // Glide
    ksp(libs.glide.compiler)

}
@Singleton
@Component(
    modules = [
        AndroidSupportInjectionModule::class, // Default module, always on top
        AppModule::class,
        CommonModule::class,
        ViewModelFactoryModule::class, // Injecting ViewModel happens here
        ActivityBuildersModule::class, // Injecting Activity and Fragment happens here
        ServiceBuilderModule::class // Injecting Service happens here
    ]
)
interface AppComponent : AndroidInjector<App> {

    // Override the builder
    @Component.Builder
    interface Builder {

        // We can now access and inject Application class anywhere in this project
        // as long as that consumer class is also injected/registered in Dagger
        @BindsInstance
        fun application(application: Application): Builder

        fun build(): AppComponent

    }

}
class App : DaggerApplication() {

    // Injecting some instance here

    override fun onCreate() {
        super.onCreate()
        ...
    }

    override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
        val appComponent = DaggerAppComponent.builder().application(this).build()
        appComponent.inject(this)
        return appComponent
    }

}

Module: app:common

plugins {
    id(libs.plugins.android.library.get().pluginId)
    alias(libs.plugins.android.kotlin) // This should be put before any Kotlin dependent plugin
    alias(libs.plugins.ksp)
}
dependencies {

    // Dagger 2
    api(libs.dagger)
    api(libs.dagger.android.support) // If using support libraries
    ksp(libs.dagger.compiler)
    ksp(libs.dagger.android.processor)

    // Glide
    api(libs.glide)
    ksp(libs.glide.compiler)

}

@Module
class CommonModule {

   ...

    @Provides
    @Singleton
    fun provideGlideInstance(
        application: Application,
        requestOptions: RequestOptions
    ): RequestManager = Glide.with(application).setDefaultRequestOptions(requestOptions)

}

Version Catalog TOML

[versions]
glide = "4.16.0"


[libraries]
# Glide
glide = { module = "com.github.bumptech.glide:glide", version.ref = "glide" }
glide-compiler = { module = "com.github.bumptech.glide:ksp", version.ref = "glide" }

Error logs


> Task :app:kspDebugKotlin FAILED
e: [ksp] InjectProcessingStep was unable to process 'glide' because 'error.NonExistentClass' could not be resolved.

Dependency trace:
    => element (CLASS): com.company.app.presentation.AssetInfoActivity
    => type (DECLARED superclass): com.company.android.common.presentation.ui.activity.BaseActivity<error.NonExistentClass,com.company.android.common.presentation.viewmodel.BaseViewModel>
    => type (ERROR type argument): 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.
e: [ksp] InjectProcessingStep was unable to process 'glide' because 'error.NonExistentClass' could not be resolved.

Dependency trace:
    => element (CLASS): com.company.app.presentation.BlogViewActivity
    => type (DECLARED superclass): com.company.android.common.presentation.ui.activity.BaseActivity<error.NonExistentClass,com.company.android.common.presentation.viewmodel.BaseViewModel>
    => type (ERROR type argument): 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.
e: [ksp] InjectProcessingStep was unable to process 'parser' because 'error.NonExistentClass' could not be resolved.


... and so on
@bcorso
Copy link

bcorso commented Dec 2, 2023

Unfortunately, none of the sources you provided are useful for this error.

The error message is saying that there is a type that could not be resolved, and the dependency trace tells you where that type is located. For example:

Dependency trace:
    => element (CLASS): com.company.app.presentation.AssetInfoActivity
    => type (DECLARED superclass): com.company.android.common.presentation.ui.activity.BaseActivity<error.NonExistentClass,com.company.android.common.presentation.viewmodel.BaseViewModel>
    => type (ERROR type argument): error.NonExistentClass

In this case, we need to see the source for AssetInfoActivity, as it looks like the type that could not be resolved was the first type parameter of the superclass.

@ArcherEmiya05
Copy link
Author

ArcherEmiya05 commented Dec 3, 2023

Unfortunately, none of the sources you provided are useful for this error.

The error message is saying that there is a type that could not be resolved, and the dependency trace tells you where that type is located. For example:

Dependency trace:
    => element (CLASS): com.company.app.presentation.AssetInfoActivity
    => type (DECLARED superclass): com.company.android.common.presentation.ui.activity.BaseActivity<error.NonExistentClass,com.company.android.common.presentation.viewmodel.BaseViewModel>
    => type (ERROR type argument): error.NonExistentClass

In this case, we need to see the source for AssetInfoActivity, as it looks like the type that could not be resolved was the first type parameter of the superclass.

Hmm, in this activity I am injecting RequestManager of Glide.

class AssetInfoActivity : BaseActivity<ActivityAssetInfoBinding, BaseViewModel>(),
    PriceFragment.PriceListener,
    Toolbar.OnMenuItemClickListener {

    @Inject
    lateinit var glide: RequestManager

}

I cannot understand what is wrong since nothing changed in the code other than migrating to KSP.

@dmapr
Copy link

dmapr commented Dec 3, 2023

Looks like it's complaining about ActivityAssetInfoBinding. Are you using view binding or data binding?

@ArcherEmiya05
Copy link
Author

Looks like it's complaining about ActivityAssetInfoBinding. Are you using view binding or data binding?

ViewBinding

@dmapr
Copy link

dmapr commented Dec 3, 2023

Then you may want to check out the #4049 for a workaround

@ArcherEmiya05
Copy link
Author

ArcherEmiya05 commented Dec 3, 2023

Closing this due to having similarity on existing issue of KSP with ViewBinding. For now will use the suggested workaround.

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

3 participants