'Android Jetpack DataStore Fatal Exception: java.io.IOException

Im using datastore in one of my android library and I get crashes from google vitals that I cant reproduce and should not be possible...

I create my datastore as per guide:

val Context.baseDataStore by preferencesDataStore(
name = "my_pref")

This is ofcourse on the top level and outside of any class, so by default it should always be a single instance, and I access the data store by using the context.baseDataStore in my app,but then I get this from crashlytics:

Fatal Exception: java.io.IOException Unable to rename /data/user/0/com.myapp/files/datastore/my_pref.preferences_pb.tmp.This likely means that there are multiple instances of DataStore for this file. Ensure that you are only creating a single instance of datastore for this file.

Can anything be done about it?

Additional Info: It looks like it happens once on upgrade since crashlytics says its crashing in the first second. Also it looks like it is happening only once per upgrade since the occurrences are dropping to 0 after a new version release



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source