Status Update
Comments
da...@sucharda.cz <da...@sucharda.cz> #2
jb...@google.com <jb...@google.com> #3
da...@sucharda.cz <da...@sucharda.cz> #4
da...@sucharda.cz <da...@sucharda.cz> #5
In our case, we have b2b app running on dedicated devices.
After 1.1.0 DataStore update we had 6 terminals reported 30k androidx.datastore.core.CorruptionException
fatal crashes on app start.
We use DataStore in WorkManager jobs and on regular Activity starts. Seems that after the application gets this state it will never will succeed to start successfully again. I am afraid that data is being corrupted.
Can't reproduce. But same as OP, we have very vanilla usage of DataStore Preferences. No multiple processes, just simple read/write key-values in a single process single Activity.
jb...@google.com <jb...@google.com>
cl...@google.com <cl...@google.com> #6
Hi, thanks for the feedback, noticed the number of +1s, I'll prioritize an investigation.
To facilitate the process, could you please share how you create the DataStore instance?
ap...@google.com <ap...@google.com> #7
Here is how we are creating our DataStore<Preferences>
instances:
PreferenceDataStoreFactory.create(
produceFile = { context.preferencesDataStoreFile(filename) }, // filename is [a-zA-Z]
scope = scope, // CoroutineScope(Dispatchers.IO + SupervisorJob())
migrations = listOf(
SharedPreferencesMigration(
context = context,
sharedPreferencesName = sharedPrefFile, // we are using our package name here
keysToMigrate = keysToMigrate, // a Set<String>, sometimes empty if nothing to be migrated
),
),
corruptionHandler = ReplaceFileCorruptionHandler {
// logging step omitted
emptyPreferences()
},
)
And these methods are called in Hilt @Provides
methods in a @InstallIn(SingletonComponent::class) @Module
for each preferences we use in our app.
pr...@google.com <pr...@google.com> #8
@Module
@InstallIn(SingletonComponent::class)
class PreferencesDataStoreModule {
@Provides
@Singleton
fun provideDataStore(@ApplicationContext context: Context): DataStore<Preferences> =
PreferenceDataStoreFactory.create(
produceFile = {
context.preferencesDataStoreFile(PREFERENCES_FILE_NAME)
},
)
}
Description
Component used: Navigation
Version used: 2.5.1 and 2.5.2
Last known working version: 2.3.5
Devices/Android versions reproduced on: Huawei P20 Light / AN 9 (EMUI 9.1.0)
So our navigation is kinda complex so I will try to simplify the configuration. If there is a nested graph with arguments which cannot be null (and no default value is supplied) and
popUpTo
is used to remove nested graph during destination (nested) navigation it tries to recreate nested graph as a parent for the destination being navigated to.So now if the navigation is triggered like this:
It will pop fragments from back stack, but it will not change parent for
ChildFragment2
which will be set tochildNavGraph
and since it is not in the back stack anymore it will try to recreate it with default values. ButargumentLong
is not nullable and has no default value so it will crash:Note: Interesting thing is that it does not crash with non-nullable String argument for some reason (ah I see, it is because String NavType is nullable by default:
StringType: NavType<String?>
vsLongType: NavType<Long>
).Possible fixes for us:
popUpTo
to pop parent (navGraph) of a Fragment (node) from XML but usepopBackStack
from code instead.argumentLong
.Basically I am not sure if this an intended behavior or a bug. Gonna mark it as a bug because it worked in 2.3.5. I understand that Destination should have a parent but what is the reason to create a parent that does not exist and will never be displayed in this case, since it was already poped and thus it should not be displayed to the user.
At the moment two solutions come to mind:
LongType
and other types nullable same asStringType
. Again not sure if this can be done and it probably is not a proper solution (change).There might of course be other solutions that I cannot see.
Thank you for your time and help.