---
title: "Manual Setup"
description: "Learn how to set up the SDK manually."
url: https://docs.sentry.io/platforms/android/manual-setup/
---

# Manual Setup | Sentry for Android

If you can't (or prefer not to) run the [automatic setup](https://docs.sentry.io/platforms/android.md#install), you can follow the instructions below to configure your application manually.

## [Installation](https://docs.sentry.io/platforms/android/manual-setup.md#installation)

The easiest way to get started is to install the Sentry Android Gradle plugin to your app module's `build.gradle` file.

`app/build.gradle`

```groovy
plugins {
  id "com.android.application"
  id "io.sentry.android.gradle" version "6.4.0"
}
```

Version `6.4.0` of the plugin will automatically add the Sentry Android SDK (version `8.38.0`) to your app.

### [Manual Installation](https://docs.sentry.io/platforms/android/manual-setup.md#manual-installation)

If you don't want the Sentry Gradle plugin to install the Sentry SDK automatically, you can define the dependency directly in the `build.gradle` file of your app module.

`app/build.gradle`

```groovy
dependencies {
    implementation 'io.sentry:sentry-android:8.38.0'
}
```

If you're using multiple Sentry dependencies, you can add a [bill of materials](https://docs.sentry.io/platforms/android/configuration/bill-of-materials.md) to avoid specifying the version of each dependency.

## [Configuration via AndroidManifest.xml](https://docs.sentry.io/platforms/android/manual-setup.md#configuration-via-androidmanifestxml)

Configuration is done via the application `AndroidManifest.xml`. Here's an example config which should get you started:

`AndroidManifest.xml`

```xml
<application>
  <!-- Required: set your sentry.io project identifier (DSN) -->
  <meta-data
    android:name="io.sentry.dsn"
    android:value="___PUBLIC_DSN___"
  />

  <!-- Add data like request headers, user ip address and device name, see https://docs.sentry.io/platforms/android/data-management/data-collected/ for more info -->
  <meta-data
    android:name="io.sentry.send-default-pii"
    android:value="true"
  />

  <!-- enable automatic traces for user interactions (clicks, swipes, scrolls) -->
  <meta-data
    android:name="io.sentry.traces.user-interaction.enable"
    android:value="true"
  />
  <!-- enable screenshot for crashes -->
  <meta-data
    android:name="io.sentry.attach-screenshot"
    android:value="true"
  />
  <!-- enable view hierarchy for crashes -->
  <meta-data
    android:name="io.sentry.attach-view-hierarchy"
    android:value="true"
  />

  <!-- enable the performance API by setting a sample-rate, adjust in production env -->
  <meta-data
    android:name="io.sentry.traces.sample-rate"
    android:value="1.0"
  />

  <!-- Enable UI profiling, adjust in production env. This is evaluated only once per session -->
  <meta-data
    android:name="io.sentry.traces.profiling.session-sample-rate"
    android:value="1.0"
  />
  <!-- Set profiling mode. For more info see https://docs.sentry.io/platforms/android/profiling/#enabling-ui-profiling -->
  <meta-data
    android:name="io.sentry.traces.profiling.lifecycle"
    android:value="trace"
  />
  <!-- Enable profiling on app start. The app start profile will be stopped automatically when the app start root span finishes -->
  <meta-data
    android:name="io.sentry.traces.profiling.start-on-app-start"
    android:value="true"
  />

  <!-- record session replays for 100% of errors and 10% of sessions -->
  <meta-data
    android:name="io.sentry.session-replay.on-error-sample-rate"
    android:value="1.0"
  />
  <meta-data
    android:name="io.sentry.session-replay.session-sample-rate"
    android:value="0.1"
  />

  <!-- If your application has strict PII requirements we recommend using the Canvas screenshot strategy. 
  See the Android Session Replay documentation for details: https://docs.sentry.io/platforms/android/session-replay/#screenshot-strategy -->
  <!-- <meta-data android:name="io.sentry.session-replay.screenshot-strategy" android:value="canvas" /> -->

  <!-- enable logs to be sent to Sentry. Use Sentry.logger() to capture logs or check the available integrations that capture logs automatically: https://docs.sentry.io/platforms/android/logs/#integrations -->
  <meta-data android:name="io.sentry.logs.enabled" android:value="true" />

  <!-- enable tombstone support for richer Native crashes context. See more at https://docs.sentry.io/platforms/android/configuration/tombstones/ -->
  <meta-data
    android:name="io.sentry.tombstone.enable"
    android:value="true"
  />
</application>
```

Under the hood, Sentry uses a `ContentProvider` to initialize the SDK based on the values provided above. This way, the SDK can capture important crashes and metrics right from the app start.

## [Configuration via SentryOptions](https://docs.sentry.io/platforms/android/manual-setup.md#configuration-via-sentryoptions)

Initialize the SDK manually when you need to provide additional configuration to the SDK that cannot be specified in the manifest.

To initialize the SDK manually, disable the auto-initialization. You can do so by adding the following line to your manifest:

`AndroidManifest.xml`

```xml
<application>
    <meta-data android:name="io.sentry.auto-init" android:value="false" />
</application>
```

Or, to completely remove the merging of the `ContentProvider`:

`AndroidManifest.xml`

```xml
<application>
    <provider
    android:name="io.sentry.android.core.SentryInitProvider"
    android:authorities="${applicationId}.SentryInitProvider"
    tools:node="remove"
  />

    <provider
    android:name="io.sentry.android.core.SentryPerformanceProvider"
    android:authorities="${applicationId}.SentryPerformanceProvider"
    tools:node="remove"
  />
</application>
```

The next step is to initialize the SDK directly in your code.

The SDK can catch errors and crashes only after you've initialized it. For that reason, we recommend calling `SentryAndroid.init` in your Application class as soon as the application is created. If you don't already have a custom Application class, [check out the official docs on how to create one](https://developer.android.com/reference/android/app/Application).

Configuration options will be loaded from the manifest so that you don't need to have the static properties in your code. In the `init` method, you can provide a callback that will modify the configuration and also register new options.

```kotlin
import io.sentry.ScreenshotStrategyType;
import io.sentry.SentryLevel;
import io.sentry.ProfileLifecycle;
import io.sentry.android.core.SentryAndroid;
import android.app.Application;
import io.sentry.SentryOptions

class MyApplication : Application() {
  override fun onCreate() {
    super.onCreate()

    SentryAndroid.init(this) { options ->
      // Required: set your sentry.io project identifier (DSN)
      options.dsn = "___PUBLIC_DSN___"
      // Add data like request headers, user ip address and device name, see https://docs.sentry.io/platforms/android/data-management/data-collected/ for more info
      options.isSendDefaultPii = true
      // enable automatic traces for user interactions (clicks, swipes, scrolls)
      options.isEnableUserInteractionTracing = true
      // enable screenshot for crashes
      options.isAttachScreenshot = true
      // enable view hierarchy for crashes
      options.isAttachViewHierarchy = true
      // enable the performance API by setting a sample-rate, adjust in production env
      options.tracesSampleRate = 1.0
      // enable UI profiling, adjust in production env. This is evaluated only once per session
      options.profileSessionSampleRate = 1.0
      // set profiling mode. For more info see https://docs.sentry.io/platforms/android/profiling/#enabling-ui-profiling
      options.profileLifecycle = ProfileLifecycle.TRACE
      // enable profiling on app start. The app start profile will be stopped automatically when the app start root span finishes
      options.isStartProfilerOnAppStart = true
      // record session replays for 100% of errors and 10% of sessions
      options.sessionReplay.sessionSampleRate = 0.1
      options.sessionReplay.onErrorSampleRate = 1.0

      // If your application has strict PII requirements we recommend using the Canvas screenshot strategy.
      // See the Android Session Replay documentation for details: https://docs.sentry.io/platforms/android/session-replay/#screenshot-strategy
      // options.sessionReplay.screenshotStrategy = ScreenshotStrategyType.CANVAS

      // enable logs to be sent to Sentry. Use Sentry.logger() to capture logs or check the available integrations that capture logs automatically: https://docs.sentry.io/platforms/android/logs/#integrations
      options.logs.isEnabled = true;

      // enable tombstone support for richer Native crashes context. See more at https://docs.sentry.io/platforms/android/configuration/tombstones/
      options.isTombstoneEnabled = true;

      // Add a callback that will be used before the event is sent to Sentry.
      // With this callback, you can modify the event or, when returning null, also discard the event.
      options.beforeSend =
        SentryOptions.BeforeSendCallback { event, hint ->
          if (SentryLevel.DEBUG == event.level) {
            null
          } else {
            event
          }
        }
    }
  }
}
```

Additional options can be found [on our dedicated options page](https://docs.sentry.io/platforms/android/configuration/options.md).
