Skip to content

Conversation

@markushi
Copy link
Member

@markushi markushi commented Apr 8, 2025

📜 Description

If you launch a Jetpack Compose Preview for a @Composable within a library, the library will be packaged as an app (androidTest flavor) and the Compose Tooling will add a preview activity.

If the library has a dependency to Sentry, this will cause the preview-app to crash, as typically no DSN is set within the library and our SDK will try to auto-init.

There's no easy way around this, but we can detect at runtime if the app is a preview app.

💡 Motivation and Context

Fixes #2904

💚 How did you test it?

Added unit tests.

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 386.91 ms 438.86 ms 51.95 ms
Size 1.58 MiB 2.08 MiB 505.57 KiB

Previous results on branch: markushi/fix/compose-preview-crash

Startup times

Revision Plain With Sentry Diff
3bfb54f 436.36 ms 502.47 ms 66.11 ms
d6ccf6a 401.36 ms 429.28 ms 27.92 ms

App size

Revision Plain With Sentry Diff
3bfb54f 1.58 MiB 2.08 MiB 505.56 KiB
d6ccf6a 1.58 MiB 2.08 MiB 505.56 KiB

// Jetpack Compose Preview (aka "Run Preview on Device")
// uses the androidTest flavor for android library modules,
// so let's fail-fast by checking this first
if (context.getPackageName().endsWith(".test")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will cover the majority of customers already, great find 💯

Copy link
Member

@romtsn romtsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@markushi markushi merged commit f80b9e8 into main Apr 10, 2025
34 checks passed
@markushi markushi deleted the markushi/fix/compose-preview-crash branch April 10, 2025 08:05
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 this pull request may close these issues.

Crash for composable preview due to lack of DSN declaration in manifest

3 participants