Google Play Vitals reports crashes occurring on the Android devices running Android 8.0 and 8.1 which have the similar structure:
java.lang.RuntimeException:
at android.app.ActivityThread.handleBindApplication (ActivityThread.java:5743)
at android.app.ActivityThread.-wrap1 (Unknown Source)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1656)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6494)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
Caused by: java.lang.IllegalStateException:
at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:387)
at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:372)
at android.content.ContextWrapper.getSharedPreferences (ContextWrapper.java:167)
at foo.bar.core.data.UserPreferences.<init> (UserPreferences.java:11)
at foo.bar.android.core.di.AppModule.a (AppModule.java:7)
at foo.bar.android.core.di.AppModule_ProvideUserPreferencesFactory.a (AppModule_ProvideUserPreferencesFactory.java:10)
at foo.bar.android.core.di.AppModule_ProvideUserPreferencesFactory.get (AppModule_ProvideUserPreferencesFactory.java)
at dagger.internal.DoubleCheck.get (DoubleCheck.java:15)
at foo.bar.android.core.di.DaggerAppComponent.n (DaggerAppComponent.java:2)
at foo.bar.android.Application.d (FooApplication.java:9)
The strange thing is that the way I create the SharedPreferences
is pretty straightforward:
private val userPreferences: SharedPreferences = context.getSharedPreferences(USER_PREFS_FILE_NAME, Context.MODE_PRIVATE)
Another strange thing is that I am on Android 8.1 and I did not notice any crashes, while Play Vitals reports them happening on exactly the same device as the one I am using all the time: Pixel 2 XL, Android 8.1 (there're other devices with that issue as well).
Am I missing some obvious change in the SharedPreferences
introduced in Android 8.0 (the crashes are happening on both 8.0 and 8.1, but ~96% of crashes are on 8.1)?