airbnb / Showkase

🔦 Showkase is an annotation-processor based Android library that helps you organize, discover, search and visualize Jetpack Compose UI elements
https://medium.com/airbnb-engineering/introducing-showkase-a-library-to-organize-discover-and-visualize-your-jetpack-compose-elements-d5c34ef01095
Apache License 2.0
2.11k stars 107 forks source link

Fatal Exception: java.lang.RuntimeException: Unable to start activity ShowkaseBrowserActivity #366

Closed Monabr closed 9 months ago

Monabr commented 9 months ago

Hello.

With each of my releases, bots come to me and launch ShowkaseBrowserActivity, it crashes and I get bad statistics. Is there any way to fix this?

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{.../com.airbnb.android.showkase.ui.ShowkaseBrowserActivity}: com.airbnb.android.showkase.exceptions.ShowkaseException: Missing key in bundle. Please start this activity by using the intent returned by the ShowkaseBrowserActivity.getIntent() method.
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
       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:2066)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:223)
       at android.app.ActivityThread.main(ActivityThread.java:7656)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
vinaygaba commented 9 months ago

Are you manually starting the activity? You are supposed to start this activity using the ShowkaseBrowserActivity.getIntent() method. Is that what you used?

Monabr commented 9 months ago

@vinaygaba I am not using this activity, some bots launch it in my code. I am not manually starting the activity.

vinaygaba commented 9 months ago

@Monabr In that case, this activity isn't being started correctly as it needs more information to work correctly. This is an intentional failure - https://github.com/airbnb/Showkase/blob/8d9e120e5f4c1b34e3824fd07de9699876277639/showkase/src/main/java/com/airbnb/android/showkase/ui/ShowkaseBrowserActivity.kt#L23

Is there a way where you can pass additional information when this activity is started (or how this activity is started)? I suspect you do?

Monabr commented 9 months ago

@vinaygaba I am not using this activity, I am not starting it. Some other people's bots, which I have nothing to do with, enter my application and launch this activity.

vinaygaba commented 9 months ago

@Monabr Not sure how to help here if these bots are starting the activity incorrectly. I have no control over this, library is doing the right thing as it's designed to.

Monabr commented 9 months ago

@vinaygaba We need to remove this activity from the release build; it is absolutely unnecessary there, has no use and causes problems. Or do something about this crashes so that it does not spoil the statistics.

vinaygaba commented 9 months ago

You can make Showkase only available in debug builds. Make sure your setup looks like this -

debugImplementation "com.airbnb.android:showkase:1.0.2"
kspDebug "com.airbnb.android:showkase-processor:1.0.2"

implementation "com.airbnb.android:showkase-annotation:1.0.2"
Monabr commented 9 months ago

@vinaygaba I don’t use your dependencies directly; they probably came to me along with the Jetpack Compose dependencies. How could I fix the situation?

vinaygaba commented 9 months ago

@Monabr That's not possible. This library is an opt-in library and doesn't come by default if you use Jetpack Compose.

Monabr commented 9 months ago

@vinaygaba I have Lottie package with com.airbnb... maybe that activity comes from their dependencies? How could I fix the situation?

vinaygaba commented 9 months ago

Lottie doesn't use Showkase so that's not possible either. I recommend spending some more time debugging as it's unrelated to the library itself and has probably something to do with your setup.

vinaygaba commented 9 months ago

@Monabr I was able to understand the root cause of this issue -

It stems from your use of this library - https://github.com/marosseleng/compose-material3-datetime-pickers

It leverages Showkase in a way that uses it as an implementation dependency as opposed to debugImplementation like I recommended in this comment https://github.com/airbnb/Showkase/issues/366#issuecomment-1868363576. If the library added a debug dependency on Showkase, it wouldn't be available in your release builds.

Moreover, this is happening because the ShowkaseBrowserActivity used to be incorrectly exported. This was fixed here - https://github.com/airbnb/Showkase/pull/355. However, a new release hasn't gone out since this fix was merged. So even though this issue has been fixed, it's not available yet (but will be with the new release). Hope that makes sense.