Dmitry Kutyrev
Dmitry Kutyrev

Reputation: 11

Gradle can't find protobuf generated class UserPreferences in DataStore

I use Hilt and proto DataStore.

When I try to build my project, I have an error: NonExistentClass in generated modules. Gradle can't find protobuf generated class UserPreferences in DataStore. But if I remove @Provides annotation my project compiles without error.

@InstallIn(SingletonComponent::class)
@Module
object DatastoreModule {

    @Provides
    fun provideProtoDataStore(@ApplicationContext appContext: Context): DataStore<UserPreferences> {
        return DataStoreFactory.create(
            serializer = UserPreferencesSerializer,
            produceFile = { appContext.dataStoreFile(DATA_STORE_FILE_NAME) } ,
            corruptionHandler = null)
    }
}

I think that's happens because hilt task starts before protobuf codegeneration task. Can I change codegeneration tasks order in gradle?

Upvotes: 0

Views: 426

Answers (1)

Dmitry Kutyrev
Dmitry Kutyrev

Reputation: 11

Gradle flag "correctErrorTypes" helped with my issue.

kapt { correctErrorTypes = true }

Upvotes: 1

Related Questions