EdricChan03 / studybuddy-android

A study buddy with features such as tasks, resources and more!
https://studybuddy.page.link/home
MIT License
16 stars 9 forks source link

[Bug] Crash at runtime with serialization error #725

Open EdricChan03 opened 2 months ago

EdricChan03 commented 2 months ago

Is there an existing issue for this?

What happened?

When launching a nightly build of the app, it crashes at runtime.

Expected behaviour

The app should not crash at runtime, and should show a login dialog

Reproduction steps

  1. Install the latest nightly build
  2. Run the app
  3. The app should crash with an obfuscated version of the crash log above

Application variant

Release, Nightly

Application version

1.1.0

Application version code

-

Relevant log output

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.edricchan.studybuddy.nightly/com.edricchan.studybuddy.ui.modules.main.MainActivity}: sa.k: Serializer for class 'n' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.

       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3920)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4073)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2426)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:211)
       at android.os.Looper.loop(Looper.java:300)
       at android.app.ActivityThread.main(ActivityThread.java:8503)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)

Caused by sa.k: Serializer for class 'n' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.

       at kotlinx.serialization.internal.Platform_commonKt.serializerNotRegistered(Platform.common.kt:90)
       at kotlinx.serialization.SerializersKt__SerializersKt.serializer(Serializers.kt:299)
       at kotlinx.serialization.SerializersKt.serializer(Serializers.kt:1)
       at androidx.navigation.NavDestinationBuilder.<init>(NavDestinationBuilder.kt:91)
       at androidx.navigation.ActivityNavigatorDestinationBuilder.<init>(ActivityNavigatorDestinationBuilder.kt:101)
       at com.edricchan.studybuddy.navigation.compat.CompatNavigationKt.compatGraphs(CompatNavigation.kt:247)
       at com.edricchan.studybuddy.ui.modules.main.MainActivity.initNavGraph(MainActivity.kt:249)
       at com.edricchan.studybuddy.ui.modules.main.MainActivity.onCreate(MainActivity.kt:80)
       at android.app.Activity.performCreate(Activity.java:8589)
       at android.app.Activity.performCreate(Activity.java:8553)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1445)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3901)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4073)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2426)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:211)
       at android.os.Looper.loop(Looper.java:300)
       at android.app.ActivityThread.main(ActivityThread.java:8503)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)

Possible solution

When marking the nightly variant as debuggable (i.e. isDebuggable = true), adding a breakpoint to Platform.common.kt:90, and running the debuggable app, it reveals that the CompatDestination.DebugModalBottomSheet object couldn't be serialised:

Screenshot of IDE debugger with a breakpoint at Platform.common.kt:90, with the Threads and Variables tab open at the breakpoint, showing the CompatDestination.DebugModalBottomSheet object being referenced

Some comprehensive Google searching, asking around on the AndroidDev Discord server and some additional searches on Google's IssueTracker later, I finally found a relevant issue that was what I was facing: Issue 353898971.

I eventually noticed that the particular object wasn't actually used anywhere (the navigateToDebugModalBottomSheet DSL was unused, so CompatDestination.DebugModalBottomSheet was unused)

Additional context

No response