DEV Community

Kay Gosho
Kay Gosho

Posted on • Edited on

4 2

Install react-native-sentry without react-native link

[Added]
Sentry has a complete manual integration guide. It might be waste of time for you to read this article!

https://docs.sentry.io/clients/react-native/manual-setup/
[/Added]

[Added again]
Now we can use fully integrated Sentry SDK for React Native:

https://github.com/getsentry/sentry-react-native
[/Added again]

Sentry is a great tool to collect runtime errors.

react-native-sentry is an official package by Sentry. While it is still in Beta, works well.

https://github.com/getsentry/react-native-sentry

Official document uses react-native link, but I don't use it as it causes errors very often.

https://docs.sentry.io/clients/react-native/

yarn add react-native-sentry

iOS

open node_modules/react-native-sentry/ios/

Then, manually drug and drop RNSentry.xcodeproj to Xcode Library. This pattern is commonly used to install native modules to React Native apps.

See my picture here:

https://github.com/kmagiera/react-native-gesture-handler/issues/205#issuecomment-449900414

Then, add libRNSentry.a to Build phases > Link Binary With Libraries. Note that you must not add neither libRNSentryStatic.a nor Sentry.framework which causes build errors.

Android

Open android/settings.gradle and add the following lines:

include ':react-native-sentry'
project(':react-native-sentry').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sentry/android')

Then, open android/app/build.gradle and add the following lines:

dependencies {
    compile project(':react-native-sentry')
    // other code here
}

Finally, open android/app/src/main/java/com/nupp1/MainApplication.java and add the package:

package com.your.app;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import io.sentry.RNSentryPackage;  // <-- Add this line

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new RNSentryPackage()        // <-- Add this line
      );
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

I hope this helps you.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay