android.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. sourcePackageRegistries,
  10. }: Partial<
  11. Pick<ModuleProps, 'dsn' | 'sourcePackageRegistries'>
  12. > = {}): LayoutProps['steps'] => [
  13. {
  14. type: StepType.INSTALL,
  15. description: (
  16. <p>
  17. {tct(
  18. 'Add the [sagpLink:Sentry Android Gradle plugin] to your [app:app] module:',
  19. {
  20. sagpLink: (
  21. <ExternalLink href="https://docs.sentry.io/platforms/android/configuration/gradle/" />
  22. ),
  23. app: <code />,
  24. }
  25. )}
  26. </p>
  27. ),
  28. configurations: [
  29. {
  30. language: 'groovy',
  31. partialLoading: sourcePackageRegistries?.isLoading,
  32. code: `
  33. plugins {
  34. id "com.android.application" // should be in the same module
  35. id "io.sentry.android.gradle" version "${
  36. sourcePackageRegistries?.isLoading
  37. ? t('\u2026loading')
  38. : sourcePackageRegistries?.data?.['sentry.java.android.gradle-plugin']?.version ??
  39. '3.12.0'
  40. }"
  41. }
  42. `,
  43. },
  44. {
  45. description: t(
  46. 'The plugin will automatically add the Sentry Android SDK to your app.'
  47. ),
  48. },
  49. ],
  50. },
  51. {
  52. type: StepType.CONFIGURE,
  53. description: (
  54. <p>
  55. {tct(
  56. '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.',
  57. {
  58. manifest: <code />,
  59. provider: <code />,
  60. }
  61. )}
  62. </p>
  63. ),
  64. configurations: [
  65. {
  66. description: t("Here's an example config which should get you started:"),
  67. language: 'xml',
  68. code: `
  69. <application>
  70. <!-- Required: set your sentry.io project identifier (DSN) -->
  71. <meta-data android:name="io.sentry.dsn" android:value="${dsn}" />
  72. <!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->
  73. <meta-data android:name="io.sentry.traces.user-interaction.enable" android:value="true" />
  74. <!-- enable screenshot for crashes -->
  75. <meta-data android:name="io.sentry.attach-screenshot" android:value="true" />
  76. <!-- enable view hierarchy for crashes -->
  77. <meta-data android:name="io.sentry.attach-view-hierarchy" android:value="true" />
  78. <!-- enable the performance API by setting a sample-rate, adjust in production env -->
  79. <meta-data android:name="io.sentry.traces.sample-rate" android:value="1.0" />
  80. <!-- enable profiling when starting transactions, adjust in production env -->
  81. <meta-data android:name="io.sentry.traces.profiling.sample-rate" android:value="1.0" />
  82. </application>
  83. `,
  84. },
  85. ],
  86. },
  87. {
  88. type: StepType.VERIFY,
  89. description: (
  90. <p>
  91. {tct(
  92. "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].",
  93. {
  94. mainActivity: <code />,
  95. }
  96. )}
  97. </p>
  98. ),
  99. configurations: [
  100. {
  101. language: 'kotlin',
  102. code: `
  103. val breakWorld = Button(this).apply {
  104. text = "Break the world"
  105. setOnClickListener {
  106. throw RuntimeException("Break the world")
  107. }
  108. }
  109. addContentView(breakWorld, ViewGroup.LayoutParams(
  110. ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
  111. `,
  112. },
  113. ],
  114. },
  115. ];
  116. export const nextSteps = [
  117. {
  118. id: 'manual-configuration',
  119. name: t('Manual Configuration'),
  120. description: t('Customize the SDK initialization behavior.'),
  121. link: 'https://docs.sentry.io/platforms/android/configuration/manual-init/#manual-initialization',
  122. },
  123. {
  124. id: 'proguard-r8',
  125. name: t('ProGuard/R8'),
  126. description: t('Deobfuscate and get readable stacktraces in your Sentry errors.'),
  127. link: 'https://docs.sentry.io/platforms/android/configuration/gradle/#proguardr8--dexguard',
  128. },
  129. {
  130. id: 'jetpack-compose',
  131. name: t('Jetpack Compose'),
  132. description: t('Learn about our first class integration with Jetpack Compose.'),
  133. link: 'https://docs.sentry.io/platforms/android/configuration/integrations/jetpack-compose/',
  134. },
  135. {
  136. id: 'source-context',
  137. name: t('Source Context'),
  138. description: t('See your source code as part of your stacktraces in Sentry.'),
  139. link: 'https://docs.sentry.io/platforms/android/enhance-errors/source-context/',
  140. },
  141. ];
  142. // Configuration End
  143. export function GettingStartedWithAndroid({
  144. dsn,
  145. sourcePackageRegistries,
  146. ...props
  147. }: ModuleProps) {
  148. return (
  149. <Layout
  150. steps={steps({dsn, sourcePackageRegistries})}
  151. nextSteps={nextSteps}
  152. {...props}
  153. />
  154. );
  155. }
  156. export default GettingStartedWithAndroid;