android.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {t, tct} from 'sentry/locale';
  6. // Configuration Start
  7. export const steps = ({
  8. dsn,
  9. }: {
  10. dsn?: string;
  11. } = {}): LayoutProps['steps'] => [
  12. {
  13. type: StepType.INSTALL,
  14. description: (
  15. <p>
  16. {tct(
  17. 'Add the [sagpLink:Sentry Android Gradle plugin] to your [app:app] module:',
  18. {
  19. sagpLink: (
  20. <ExternalLink href="https://docs.sentry.io/platforms/android/configuration/gradle/" />
  21. ),
  22. app: <code />,
  23. }
  24. )}
  25. </p>
  26. ),
  27. configurations: [
  28. {
  29. language: 'groovy',
  30. code: `
  31. plugins {
  32. id "com.android.application" // should be in the same module
  33. id "io.sentry.android.gradle" version "3.11.1"
  34. }
  35. `,
  36. },
  37. {
  38. description: t(
  39. 'The plugin will automatically add the Sentry Android SDK to your app.'
  40. ),
  41. },
  42. ],
  43. },
  44. {
  45. type: StepType.CONFIGURE,
  46. description: (
  47. <p>
  48. {tct(
  49. 'Configuration is done via the application [manifest: AndroidManifest.xml]. Under the hood Sentry uses a [provider:ContentProvider] to initialize the SDK based on the values provided below. This way the SDK can capture important crashes and metrics right from the app start.',
  50. {
  51. manifest: <code />,
  52. provider: <code />,
  53. }
  54. )}
  55. </p>
  56. ),
  57. configurations: [
  58. {
  59. description: t("Here's an example config which should get you started:"),
  60. language: 'xml',
  61. code: `
  62. <application>
  63. <!-- Required: set your sentry.io project identifier (DSN) -->
  64. <meta-data android:name="io.sentry.dsn" android:value="${dsn}" />
  65. <!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->
  66. <meta-data android:name="io.sentry.traces.user-interaction.enable" android:value="true" />
  67. <!-- enable screenshot for crashes -->
  68. <meta-data android:name="io.sentry.attach-screenshot" android:value="true" />
  69. <!-- enable view hierarchy for crashes -->
  70. <meta-data android:name="io.sentry.attach-view-hierarchy" android:value="true" />
  71. <!-- enable the performance API by setting a sample-rate, adjust in production env -->
  72. <meta-data android:name="io.sentry.traces.sample-rate" android:value="1.0" />
  73. <!-- enable profiling when starting transactions, adjust in production env -->
  74. <meta-data android:name="io.sentry.traces.profiling.sample-rate" android:value="1.0" />
  75. </application>
  76. `,
  77. },
  78. ],
  79. },
  80. {
  81. type: StepType.VERIFY,
  82. description: (
  83. <p>
  84. {tct(
  85. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected. You can add it to your app's [mainActivity: MainActivity].",
  86. {
  87. mainActivity: <code />,
  88. }
  89. )}
  90. </p>
  91. ),
  92. configurations: [
  93. {
  94. language: 'kotlin',
  95. code: `
  96. val breakWorld = Button(this).apply {
  97. text = "Break the world"
  98. setOnClickListener {
  99. throw RuntimeException("Break the world")
  100. }
  101. }
  102. addContentView(breakWorld, ViewGroup.LayoutParams(
  103. ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
  104. `,
  105. },
  106. ],
  107. },
  108. ];
  109. export const nextSteps = [
  110. {
  111. id: 'manual-configuration',
  112. name: t('Manual Configuration'),
  113. description: t('Customize the SDK initialization behavior.'),
  114. link: 'https://docs.sentry.io/platforms/android/configuration/manual-init/#manual-initialization',
  115. },
  116. {
  117. id: 'proguard-r8',
  118. name: t('ProGuard/R8'),
  119. description: t('Deobfuscate and get readable stacktraces in your Sentry errors.'),
  120. link: 'https://docs.sentry.io/platforms/android/configuration/gradle/#proguardr8--dexguard',
  121. },
  122. {
  123. id: 'jetpack-compose',
  124. name: t('Jetpack Compose'),
  125. description: t('Learn about our first class integration with Jetpack Compose.'),
  126. link: 'https://docs.sentry.io/platforms/android/configuration/integrations/jetpack-compose/',
  127. },
  128. {
  129. id: 'source-context',
  130. name: t('Source Context'),
  131. description: t('See your source code as part of your stacktraces in Sentry.'),
  132. link: 'https://docs.sentry.io/platforms/android/enhance-errors/source-context/',
  133. },
  134. ];
  135. // Configuration End
  136. export function GettingStartedWithAndroid({dsn, ...props}: ModuleProps) {
  137. return <Layout steps={steps({dsn})} nextSteps={nextSteps} {...props} />;
  138. }
  139. export default GettingStartedWithAndroid;