How to make sentry auto detect error/crash in android

Viewed 1369

Is it possible to send errors/crash reports automatically on android in every activity Or is it completely manual and should i use the manifest configuration or sentry.properties, Sorry i am new to Sentry, i have used manual error capturing but is automatic possible

Existing code for manual error handling

AndroidManifest.xml configuration

<meta-data android:name="io.sentry.dsn" android:value="dsn" />

MainActivity.kt

Sentry.init("dsn", AndroidSentryClientFactory(this.applicationContext))
       try {
            Log.d("sentrytest1","try")
             throw Exception("This is a test.")

        } catch (e: Exception) {
            Log.d("sentrytest1","catch")
            Sentry.capture(e)
        }
1 Answers

The Sentry Android SDK will capture exceptions automatically if they are not handled by your code (through a catch block). That includes crashes from native libraries (C/C++) that you might use directly or indirectly via JNI. These are crashes.

That said, if you're handling the error, and would like the app to continue running, but you would like to send this error to Sentry so you can be aware/investigate it, you can do that with Sentry.captureException(e);

I noticed in your example that you're mixing the initialization of the Sentry Android SDK version 1 and 2.

The Sentry Android v2 initializes itself automatically, all you need to do is to set the dsn in the manifest as you did in your example. There's no need to call Sentry.init unless you'd like to customize a few things (like a beforeSend callback).

You can find this information and more on the SDK documentation.

Related