Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes when tracking DerivedState #123

Closed
lulumeya opened this issue Mar 5, 2024 · 10 comments · Fixed by #125
Closed

App crashes when tracking DerivedState #123

lulumeya opened this issue Mar 5, 2024 · 10 comments · Fixed by #125
Assignees

Comments

@lulumeya
Copy link

lulumeya commented Mar 5, 2024

Reproduce Step : Just launch app with this plugin applied.
composeBomVersion = "2023.10.01"
composeCompiler = "1.5.10"

Stacktrace:

java.lang.RuntimeException: Unable to resume activity {com.gangnam.sister.debug/com.kotlin.activity.MainActivity}: java.lang.ClassCastException: androidx.compose.runtime.DerivedSnapshotState cannot be cast to androidx.compose.runtime.snapshots.SnapshotMutableState at android.app.ActivityThread.performResumeActivity(ActivityThread.java:5426) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:5507) at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:57) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:180) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:98) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2685) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:230) at android.os.Looper.loop(Looper.java:319) at android.app.ActivityThread.main(ActivityThread.java:8913) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103) Caused by: java.lang.ClassCastException: androidx.compose.runtime.DerivedSnapshotState cannot be cast to androidx.compose.runtime.snapshots.SnapshotMutableState at land.sungbin.composeinvestigator.runtime.ComposeStateObjectValueGetter.getCurrentValue(StateObjectTracker.kt:234) at land.sungbin.composeinvestigator.runtime.ComposeStateObjectValueGetter.initialize$runtime_release(StateObjectTracker.kt:240) at land.sungbin.composeinvestigator.runtime.StateObjectTrackerKt$registerStateObjectTracking$1$register$2$1.onRemembered(StateObjectTracker.kt:159) at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers(Composition.kt:1295) at androidx.compose.runtime.CompositionImpl.applyChangesInLocked(Composition.kt:984) at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:1005) at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:1099) at androidx.compose.runtime.CompositionImpl.composeInitial(Composition.kt:633) at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:619) at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:123) at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:114) at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:1289) at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:114) at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:164) at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.kt:314) at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.kt:251) at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.kt:287) at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.kt:136) at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.kt:119) at androidx.fragment.app.FragmentViewLifecycleOwner.handleLifecycleEvent(FragmentViewLifecycleOwner.java:100) at androidx.fragment.app.Fragment.restoreViewState(Fragment.java:708) at androidx.fragment.app.Fragment.restoreViewState(Fragment.java:3176) at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:3161) at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:619) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:275) at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943) 2024-03-05 13:21:40.287 26853-26853 AndroidRuntime com.gangnam.sister.debug E at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1839) at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1751) at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:323) at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:249) at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244) at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092) at androidx.viewpager.widget.ViewPager.setAdapter(ViewPager.java:540) at com.kotlin.activity.MainActivity.initAdapter(MainActivity.kt:601) at com.kotlin.presenter.MainPresenter.onResume(MainPresenter.kt:78) at com.kotlin.activity.MainActivity.onResume(MainActivity.kt:561) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1603) at android.app.Activity.performResume(Activity.java:9119) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:5399) ... 13 more

@jisungbin
Copy link
Owner

Thank you for reporting. I will hotfix and release a new version today.

@jisungbin jisungbin linked a pull request Mar 5, 2024 that will close this issue
@jisungbin
Copy link
Owner

jisungbin commented Mar 5, 2024

This issue was caused by trying to track DerivedState, so I added the corresponding code and released it as 1.5.10-0.1.1-SNAPSHOT.

Since it is not yet stable released, please add Snapshot Maven as follows:

repositories {
  // ...
  maven {
    url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
  }
}

I reproduced this issue using the 1.5.10-0.1.1-SNAPSHOT version and now it looks fixed.

@jisungbin
Copy link
Owner

@lulumeya Please try the new version and let us know if the issue is resolved.

@lulumeya
Copy link
Author

lulumeya commented Mar 5, 2024

Did you publish the artifact? My build script could not resolve the dependency. (I surely added the snapshot repo)

@jisungbin
Copy link
Owner

jisungbin commented Mar 5, 2024

Did you publish the artifact? My build script could not resolve the dependency. (I surely added the snapshot repo)

Have you also added it to pluginManagement's repository? The links below are examples of my application.

(You can see it released in the real repository: https://s01.oss.sonatype.org/content/repositories/snapshots/land/sungbin/composeinvestigator/)

If all goes well, I plan to release 1.5.10-0.2.0 this week with additional features.

@jisungbin jisungbin changed the title App Crashes App crashes when tracking DerivedState Mar 5, 2024
@lulumeya
Copy link
Author

lulumeya commented Mar 5, 2024

image

I tried new version but there's no luck.
It looks like the plugin dependency causes my dependency graph changes a lot.
Thus it's difficult to address the exact problem.

@jisungbin
Copy link
Owner

jisungbin commented Mar 5, 2024

@lulumeya Issues that make significant changes to the dependency graph are outside the scope of this issue, so please create a separate issue.

Anyway, to answer your comment, no dependencies changed between 0.1.0 and 0.1.1-SNAPSHOT, so you need to confirm that the dependency graph changes are indeed caused by applying 0.1.1-SNAPSHOT.

And did applying 0.1.1-SNAPSHOT resolve this issue? If it did, I'll be release 0.1.1 stable.

@lulumeya
Copy link
Author

lulumeya commented Mar 5, 2024

The issue not resolved and the dependency graph changes might be cause of this issue. So I mentioned it because the compose API rapidly changes.
I think, it will be better to release the plugin separately by the versions of Compose regarding this issue.

@jisungbin
Copy link
Owner

jisungbin commented Mar 5, 2024

ComposeInvestigator also depends a bit on the version of the Compose Runtime, so I'll take your advice and specify the tested Compose Runtime version in the documentation. Thanks!

And the last tested (0.1.1-SNAPSHOT) Compose Runtime version is 1.6.2 (currently the latest version), and the Compose Runtime version provided in the Compose BOM (2023.10.01) you are using is 1.5.4. I think the different Compose Runtime versions may have an effect.

You can override the Compose Runtime version even if you use the BOM.

implementation 'androidx.compose.runtime:runtime:1.6.2'

If you can upgrade your Compose Runtime version to 1.6.2, please check if 1.6.2 fixes this issue!

@jisungbin
Copy link
Owner

Additionally, I tested it by applying the 2023.10.01 BOM with 0.1.1-SNAPSHOT, and this issue appears to have been resolved.

image

If you downgrade to 0.1.0 (same BOM version), the issue will be reproduced.

image

If this issue still occurs, please open a new issue with a new stacktrace. It appears to be resolved now, so I'll release 0.1.1.

@jisungbin jisungbin self-assigned this Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants