I have a React Native application where Sentry is already setup and working flawlessly. However, I’d like to capture errors from Android’s native code as well, so I followed this documentation https://docs.sentry.io/platforms/android/. Even though I followed it exactly as the instructions say, I still can’t capture error from the native code.
Here is my git diff (you can also see it here):
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 14bc362..45da630 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -135,6 +135,10 @@ def enableHermes = project.ext.react.get("enableHermes", false);
def computedVersionCode = getVersionCode()
def computedVersionName = getVersionName()
+repositories {
+ jcenter()
+}
+
android {
compileSdkVersion rootProject.ext.compileSdkVersion
@@ -210,6 +214,7 @@ dependencies {
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
+ implementation 'io.sentry:sentry-android:2.3.0'
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index a71edde..faee2e2 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -26,6 +26,7 @@
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
+ <meta-data android:name="io.sentry.dsn" android:value="https://54f37a5a169c439ead943ba92ece15f2@o422688.ingest.sentry.io/5351715" />
</application>
</manifest>
diff --git a/android/app/src/main/java/studio/moxy/rnwm/MainActivity.java b/android/app/src/main/java/studio/moxy/rnwm/MainActivity.java
index e03977a..845a65b 100644
--- a/android/app/src/main/java/studio/moxy/rnwm/MainActivity.java
+++ b/android/app/src/main/java/studio/moxy/rnwm/MainActivity.java
@@ -5,6 +5,8 @@ import android.os.Bundle;
import com.facebook.react.ReactActivity;
import com.zoontek.rnbootsplash.RNBootSplash;
+import io.sentry.core.Sentry;
+
public class MainActivity extends ReactActivity {
/**
@@ -20,5 +22,10 @@ public class MainActivity extends ReactActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RNBootSplash.init(R.drawable.bootsplash, MainActivity.this); // <- display the generated bootsplash.xml drawable over our MainActivity
+ try {
+ throw new Exception("This is a test from native Android code.");
+ } catch (Exception e) {
+ Sentry.captureException(e);
+ }
}
}