russhwolf / multiplatform-settings

A Kotlin Multiplatform library for saving simple key-value data
Apache License 2.0
1.69k stars 67 forks source link

[Crash] com.russhwolf.settings.SettingsInitializer #191

Closed danidiprana closed 2 months ago

danidiprana commented 8 months ago

Reproducible Not sure, I can't reproduce this crash but there are crashes on Firebase crashlytics.

Version 1.1.0 We use this version because version 1.1.1 uses Kotlin 1.9.20 and our JS test is not ready for that. We're using settings-no-arg.

Stacktrace

Fatal Exception: java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: androidx.startup.StartupException: java.lang.ClassNotFoundException: com.russhwolf.settings.SettingsInitializer
       at android.app.ActivityThread.installProvider(ActivityThread.java:6988)
       at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445)
       at android.app.ActivityThread.access$1300(ActivityThread.java:219)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7356)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by androidx.startup.StartupException: java.lang.ClassNotFoundException: com.russhwolf.settings.SettingsInitializer
       at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:242)
       at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:206)
       at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:45)
       at android.content.ContentProvider.attachInfo(ContentProvider.java:2092)
       at android.content.ContentProvider.attachInfo(ContentProvider.java:2066)
       at android.app.ActivityThread.installProvider(ActivityThread.java:6983)
       at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445)
       at android.app.ActivityThread.access$1300(ActivityThread.java:219)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7356)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Discussion Since we're using settings-no-arg then it will initialize the settings using Initializer from the androidx on Manifest. Somehow it's crashed due to class Not found. Any idea?

Thank you.

russhwolf commented 6 months ago

This is hard to diagnose without seeing your project. Where and when do you first access Settings()? Does that access occur in a different module than the one where you depend on multiplatform-settings-no-arg?

russhwolf commented 2 months ago

SettingsInitializer is now public in version 1.2.0. Can you try upgrading and see if the crash still occurs?

danidiprana commented 2 months ago

Great!! it works now. Thanks @russhwolf