Resolving error.NonExistentClass in dagger
Recently ran into a problem where providing the generated type of sqldelight database directly into the dagger graph from module classes would fail with error.NonExistentClass
error. Failure seemed to be happening randomly if one would invoke the clean
task before assemble
.
This seems to be a limitation of the kapt since all non-existent types in the declaration are replaced by NonExistentClass
, which is an issue for our dagger dependency. For a workaround it’s recommended to set error type inference in stubs using:
kapt {
correctErrorTypes = true
}
which didn’t work.
What at the end worked, was wrapping the generated SQL type into a wrapper class and providing it in the module instead. I’ll leave a snippet to do the explanation:
@Module
@InstallIn(SingletonComponent::class)
class DatabaseModule {
@Singleton
@Provides
fun providesDatabase(@ApplicationContext appContext: Context) =
DatabaseWrapper(appContext)
}
class DatabaseWrapper(context: Context) {
val db = GeneratedDatabase(DatabaseDriverFactory(context).createDriver())
}
Read other posts