android.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import List from 'sentry/components/list/';
  4. import ListItem from 'sentry/components/list/listItem';
  5. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  6. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  7. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  8. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  9. import {t, tct} from 'sentry/locale';
  10. interface StepsParams {
  11. dsn: string;
  12. hasPerformance: boolean;
  13. hasProfiling: boolean;
  14. sourcePackageRegistries?: ModuleProps['sourcePackageRegistries'];
  15. }
  16. // Configuration Start
  17. export const steps = ({
  18. dsn,
  19. sourcePackageRegistries,
  20. hasPerformance,
  21. hasProfiling,
  22. }: StepsParams): LayoutProps['steps'] => [
  23. {
  24. title: t('Auto-Install'),
  25. description: (
  26. <p>
  27. {tct(
  28. 'Add Sentry automatically to your app with the [wizardLink:Sentry wizard] (call this inside your project directory).',
  29. {
  30. wizardLink: (
  31. <ExternalLink href="https://docs.sentry.io/platforms/android/#install" />
  32. ),
  33. }
  34. )}
  35. </p>
  36. ),
  37. configurations: [
  38. {
  39. language: 'bash',
  40. code: `brew install getsentry/tools/sentry-wizard && sentry-wizard -i android`,
  41. },
  42. {
  43. description: (
  44. <Fragment>
  45. {t('The Sentry wizard will automatically patch your application:')}
  46. <List symbol="bullet">
  47. <ListItem>
  48. {tct(
  49. "Update your app's [buildGradle:build.gradle] file with the Sentry Gradle plugin and configure it.",
  50. {
  51. buildGradle: <code />,
  52. }
  53. )}
  54. </ListItem>
  55. <ListItem>
  56. {tct(
  57. 'Update your [manifest: AndroidManifest.xml] with the default Sentry configuration',
  58. {
  59. manifest: <code />,
  60. }
  61. )}
  62. </ListItem>
  63. <ListItem>
  64. {tct(
  65. 'Create [sentryProperties: sentry.properties] with an auth token to upload proguard mappings (this file is automatically added to [gitignore: .gitignore])',
  66. {
  67. sentryProperties: <code />,
  68. gitignore: <code />,
  69. }
  70. )}
  71. </ListItem>
  72. <ListItem>
  73. {t(
  74. "Add an example error to your app's Main Activity to verify your Sentry setup"
  75. )}
  76. </ListItem>
  77. </List>
  78. <p>
  79. {tct(
  80. 'Alternatively, you can also [manualSetupLink:set up the SDK manually]. [stepsBelow: You can skip the steps below when using the wizard].',
  81. {
  82. manualSetupLink: (
  83. <ExternalLink href="https://docs.sentry.io/platforms/android/manual-setup/" />
  84. ),
  85. stepsBelow: <strong />,
  86. }
  87. )}
  88. </p>
  89. </Fragment>
  90. ),
  91. },
  92. ],
  93. },
  94. {
  95. title: t('Or Manually Install and Configure'),
  96. description: (
  97. <Fragment>
  98. <strong>{t('Install the Sentry SDK:')}</strong>
  99. <p>
  100. {tct(
  101. 'Add the [sagpLink:Sentry Android Gradle plugin] to your [app:app] module:',
  102. {
  103. sagpLink: (
  104. <ExternalLink href="https://docs.sentry.io/platforms/android/configuration/gradle/" />
  105. ),
  106. app: <code />,
  107. }
  108. )}
  109. </p>
  110. </Fragment>
  111. ),
  112. configurations: [
  113. {
  114. language: 'groovy',
  115. partialLoading: sourcePackageRegistries?.isLoading,
  116. code: `
  117. plugins {
  118. id "com.android.application" // should be in the same module
  119. id "io.sentry.android.gradle" version "${
  120. sourcePackageRegistries?.isLoading
  121. ? t('\u2026loading')
  122. : sourcePackageRegistries?.data?.['sentry.java.android.gradle-plugin']?.version ??
  123. '3.12.0'
  124. }"
  125. }
  126. `,
  127. },
  128. {
  129. description: (
  130. <Fragment>
  131. <strong>{t('Configure the Sentry SDK:')}</strong>
  132. <p>
  133. {tct(
  134. '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.',
  135. {
  136. manifest: <code />,
  137. provider: <code />,
  138. }
  139. )}
  140. </p>
  141. <p>{t("Here's an example config which should get you started:")}</p>
  142. </Fragment>
  143. ),
  144. language: 'xml',
  145. code: `
  146. <application>
  147. <!-- Required: set your sentry.io project identifier (DSN) -->
  148. <meta-data android:name="io.sentry.dsn" android:value="${dsn}" />
  149. <!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->
  150. <meta-data android:name="io.sentry.traces.user-interaction.enable" android:value="true" />
  151. <!-- enable screenshot for crashes -->
  152. <meta-data android:name="io.sentry.attach-screenshot" android:value="true" />
  153. <!-- enable view hierarchy for crashes -->
  154. <meta-data android:name="io.sentry.attach-view-hierarchy" android:value="true" />${
  155. hasPerformance
  156. ? `
  157. <!-- enable the performance API by setting a sample-rate, adjust in production env -->
  158. <meta-data android:name="io.sentry.traces.sample-rate" android:value="1.0" />`
  159. : ''
  160. }${
  161. hasProfiling
  162. ? `
  163. <!-- enable profiling when starting transactions, adjust in production env -->
  164. <meta-data android:name="io.sentry.traces.profiling.sample-rate" android:value="1.0" />`
  165. : ''
  166. }
  167. </application>
  168. `,
  169. },
  170. ],
  171. },
  172. {
  173. type: StepType.VERIFY,
  174. description: (
  175. <p>
  176. {tct(
  177. "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].",
  178. {
  179. mainActivity: <code />,
  180. }
  181. )}
  182. </p>
  183. ),
  184. configurations: [
  185. {
  186. language: 'kotlin',
  187. code: `
  188. val breakWorld = Button(this).apply {
  189. text = "Break the world"
  190. setOnClickListener {
  191. throw RuntimeException("Break the world")
  192. }
  193. }
  194. addContentView(breakWorld, ViewGroup.LayoutParams(
  195. ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
  196. `,
  197. },
  198. ],
  199. },
  200. ];
  201. export const nextSteps = [
  202. {
  203. id: 'manual-configuration',
  204. name: t('Manual Configuration'),
  205. description: t('Customize the SDK initialization behavior.'),
  206. link: 'https://docs.sentry.io/platforms/android/configuration/manual-init/#manual-initialization',
  207. },
  208. {
  209. id: 'proguard-r8',
  210. name: t('ProGuard/R8'),
  211. description: t('Deobfuscate and get readable stacktraces in your Sentry errors.'),
  212. link: 'https://docs.sentry.io/platforms/android/configuration/gradle/#proguardr8--dexguard',
  213. },
  214. {
  215. id: 'jetpack-compose',
  216. name: t('Jetpack Compose'),
  217. description: t('Learn about our first class integration with Jetpack Compose.'),
  218. link: 'https://docs.sentry.io/platforms/android/configuration/integrations/jetpack-compose/',
  219. },
  220. {
  221. id: 'source-context',
  222. name: t('Source Context'),
  223. description: t('See your source code as part of your stacktraces in Sentry.'),
  224. link: 'https://docs.sentry.io/platforms/android/enhance-errors/source-context/',
  225. },
  226. ];
  227. // Configuration End
  228. export function GettingStartedWithAndroid({
  229. dsn,
  230. sourcePackageRegistries,
  231. activeProductSelection = [],
  232. ...props
  233. }: ModuleProps) {
  234. const hasPerformance = activeProductSelection.includes(
  235. ProductSolution.PERFORMANCE_MONITORING
  236. );
  237. const hasProfiling = activeProductSelection.includes(ProductSolution.PROFILING);
  238. return (
  239. <Layout
  240. steps={steps({dsn, sourcePackageRegistries, hasPerformance, hasProfiling})}
  241. nextSteps={nextSteps}
  242. {...props}
  243. />
  244. );
  245. }
  246. export default GettingStartedWithAndroid;