forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Description
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
Metadata
Metadata
Assignees
Labels
No labels