https://kotlinlang.org logo
#compose-android
Title
# compose-android
a

ascii

11/21/2023, 2:40 AM
Man, debugging Compose crashes is a nightmare. We're getting this with 1.6.0-beta01, and Crashlytics says it's an "early crash" (within 5s):
Copy code
Fatal Exception: java.lang.IllegalArgumentException
MutableState containing (2131755159, 17039370) cannot be saved using the current SaveableStateRegistry. The default implementation only supports types which can be stored inside the Bundle. Please consider implementing a custom Saver for this class and pass it as a stateSaver parameter to rememberSaveable().
I did a quick search for an existing issue, but couldn't find any. Waiting a bit before filing it just in case I missed something. Full stack trace in thread.
1
Copy code
androidx.compose.runtime.saveable.RememberSaveableKt.requireCanBeSaved (RememberSaveable.kt:242)
androidx.compose.runtime.saveable.RememberSaveableKt.access$requireCanBeSaved (RememberSaveable.kt:1)
androidx.compose.runtime.saveable.SaveableHolder.register (RememberSaveable.kt:182)
androidx.compose.runtime.saveable.SaveableHolder.onRemembered (RememberSaveable.kt:193)
androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers (Composition.kt:1276)
androidx.compose.runtime.CompositionImpl.applyChangesInLocked (Composition.kt:973)
androidx.compose.runtime.CompositionImpl.applyChanges (Composition.kt:994)
androidx.compose.runtime.Recomposer.composeInitial$runtime_release (Recomposer.kt:1087)
androidx.compose.runtime.CompositionImpl.composeInitial (Composition.kt:629)
androidx.compose.runtime.CompositionImpl.setContent (Composition.kt:615)
androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke (WrappedComposition.java:123)
androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke (WrappedComposition.java:114)
androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable (AndroidComposeView.android.kt:1290)
androidx.compose.ui.platform.WrappedComposition.setContent (Wrapper.android.kt:114)
androidx.compose.ui.platform.WrappedComposition.onStateChanged (Wrapper.android.kt:164)
androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent (LifecycleRegistry.kt:322)
androidx.lifecycle.LifecycleRegistry.addObserver (LifecycleRegistry.kt:199)
androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke (WrappedComposition.java:121)
androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke (WrappedComposition.java:114)
androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow (AndroidComposeView.android.kt:1365)
android.view.View.dispatchAttachedToWindow (View.java:21506)
android.view.ViewGroup.dispatchAttachedToWindow (ViewGroup.java:3541)
android.view.ViewGroup.dispatchAttachedToWindow (ViewGroup.java:3548)
android.view.ViewGroup.dispatchAttachedToWindow (ViewGroup.java:3548)
android.view.ViewGroup.dispatchAttachedToWindow (ViewGroup.java:3548)
android.view.ViewGroup.dispatchAttachedToWindow (ViewGroup.java:3548)
android.view.ViewGroup.dispatchAttachedToWindow (ViewGroup.java:3548)
android.view.ViewGroup.dispatchAttachedToWindow (ViewGroup.java:3548)
android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2981)
android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:2458)
android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:9488)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:1412)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:1420)
android.view.Choreographer.doCallbacks (Choreographer.java:1047)
android.view.ChoreographerExtImpl.checkScrollOptSceneEnable (ChoreographerExtImpl.java:451)
android.view.Choreographer.doFrame (Choreographer.java:918)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1395)
android.os.Handler.handleCallback (Handler.java:942)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loopOnce (Looper.java:240)
android.os.Looper.loop (Looper.java:351)
android.app.ActivityThread.main (ActivityThread.java:8423)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:584)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1013)
No idea where
(<tel:2131755159|2131755159>, 17039370)
is coming from.
k

Kirill Grouchnikov

11/21/2023, 2:55 AM
Convert these two to hexadecimal and see if you have an xml resource that matches by ID
🤯 1
a

ascii

11/21/2023, 3:03 AM
Oh that's a brilliant idea.
17039370 -> 0x0104000a -> android.R.string.ok
Narrowed it down to a saveable
IntIntPair
we're creating.
But that's a value class and should be inlined to Long, which can certainly be stored in a bundle
Lovely. A colleague had put this warning in but someone else ignored it. It makes sense why
autoSaver()
can't be used in this case, but I wish it was more obvious to the caller.
Thanks @Kirill Grouchnikov!
👍 1
s

Stylianos Gakis

11/21/2023, 7:57 AM
Wow never would've guessed to do this myself. What a nice trick
c

Colton Idle

11/21/2023, 5:56 PM
TIL. That's awesome. thanks @Kirill Grouchnikov
85 Views