Installation

Adding the React Native packages, getting access to the private native SDKs, setting them up with the Expo config plugin, the setup wizard or by hand, and starting the SDK.

Installation has a JavaScript half and a native half. The JavaScript half is one package and one initialize call. The native half — a Gradle plugin and a config file on Android, a pod and an initializer on iOS — can be done for you by the Expo config plugin or the setup wizard, or by hand.

Quick start

Enter the collector URL, project, app and app key below and pick a tab (JS init · Android config · iOS plist) to generate the snippet from those values. The JS init tab shows the JavaScript initialize call together with the Android config file, since JS can't set the Android side. This section only generates configuration values — pick the install method itself in Choose a route below. Advanced options are behind the "Advanced options" toggle.

// App.tsx — call before rendering, e.g. at the top of index.js
import { initialize } from '@sophonz/react-native';

await initialize({
  sdkConfig: {
    ios: {
      collectorUrl: 'https://in.sophonz.ai',
      appKey: 'sk_tYtJUa4WweXXedj6lxjSqoPW5O0DnbXz',
      appName: 'next-sample',
      project: 'sophonz',
    },
  },
});

// android/app/src/main/sophonz-config.json — Android reads nothing from JS;
// this file is the only way to set its identity.
{
  "sdk_config": {
    "app_framework": "react_native",
    "ingest": {
      "collector_url": "https://in.sophonz.ai",
      "service_key": "sk_tYtJUa4WweXXedj6lxjSqoPW5O0DnbXz",
      "service_namespace": "sophonz"
    }
  }
}

Requirements

ItemRequirement
React Nativereact-native 0.56 or later is accepted as a peer dependency; the SDK is built and tested against 0.85 and 0.86
Expo (optional)expo 47 or later is accepted; the config plugin is tested against Expo SDK 57. Expo Go is not supported
ArchitectureNew and old architecture. Nothing to configure; the module compiles for whichever the app uses
Android minSdk21 or higher. Below 26, core library desugaring is required — see below
Android buildcompileSdk 34 or higher, AGP 8.0.2 or higher (8.3.0 when minSdk is below 26), Kotlin 2.0.21
iOS13.0 or higher, Swift 5.9, Xcode 26 or higher (the Apple SDK is built from source)
SPM on iOS (optional)React Native 0.75 or later, dynamic frameworks
NodeThe packages declare no engine. The setup wizard needs Node 18 or later

The Android and iOS rows are the native SDKs' own requirements; see Android installation and iOS installation for the details behind them.

Android minSdk and desugaring

The Android SDK itself supports minSdk 21. The React Native modules compile with the minSdkVersion your root android/build.gradle sets in ext, and fall back to 24 when it is not set. React Native's own templates set 24.

When the app's minSdk is below 26, the Sophonz Gradle plugin checks three things at configuration time and fails the build if any is missing:

  • core library desugaring is enabled in the app module
  • AGP is 8.3.0 or later
  • android.useFullClasspathForDexingTransform=true is in android/gradle.properties

A default React Native app (minSdk 24) therefore needs this in android/app/build.gradle:

android/app/build.gradle
android {
  compileOptions {
    coreLibraryDesugaringEnabled true
  }
}
 
dependencies {
  coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.0.3"
}
android/gradle.properties
android.useFullClasspathForDexingTransform=true

Or raise minSdk to 26, which removes all three checks. Neither the Expo config plugin nor the setup wizard makes this change for you.

Choose a route

RouteWho does the native setupWhere the SDK starts
ExpoThe config plugin, during npx expo prebuildNatively, in MainApplication and AppDelegate
Bare React Native, wizardTwo scripts you run onceNatively, in MainApplication and AppDelegate
Bare React Native, by handYouNatively, or from JavaScript — your choice

Starting natively captures crashes and startup before JavaScript loads. Starting from JavaScript lets you pass iOS options and OTLP exporters from initialize. You cannot have both for the same launch: see Native start or JavaScript start.

1. Add the packages

The packages are on npm under @sophonz. The current release is 0.1.0, and all five packages share that version.

npm install @sophonz/react-native@0.1.0
# or
yarn add @sophonz/react-native@0.1.0
# or, in an Expo app
npx expo install @sophonz/react-native@0.1.0

Optional packages, added the same way at the same version:

npm install @sophonz/react-native-tracer-provider@0.1.0 \
  @sophonz/react-native-navigation@0.1.0 \
  @sophonz/react-native-redux@0.1.0 \
  @sophonz/react-native-otlp@0.1.0
PackagePurposeNative code
@sophonz/react-nativeCore bindings, error handlers, logs, sessions, Expo config pluginYes
@sophonz/react-native-tracer-providerOpenTelemetry TracerProvider backed by the native SDKsYes
@sophonz/react-native-navigationScreen spansNo
@sophonz/react-native-reduxSpans for dispatched Redux actionsNo
@sophonz/react-native-otlpExtra OTLP/HTTP exporters alongside the collectorYes

Packages with native code need a rebuild of the app, and on iOS a pod install, after they are added.

2. Access to the native SDKs

0.1.0 binds to the Android SDK 1.0.0 and the Apple SDK 1.0.0. Neither is on a public registry, so every machine that builds the app — your laptop, CI, EAS — needs credentials for both.

Android: GitHub Packages

The Android SDK, its internal API artifact and the Gradle plugin are read from https://maven.pkg.github.com/sophonz-labs/sophonz-android-sdk, which requires a token even to read. Use a classic token with read:packages from an account that can see sophonz-labs.

~/.gradle/gradle.properties
gpr.user=<your GitHub user>
gpr.key=<token with read:packages>

When those properties are absent, the build reads the GITHUB_ACTOR and GITHUB_TOKEN environment variables instead, which is the form to use on CI.

CAUTION — A 404 is usually a credentials problem

GitHub Packages answers 404 rather than 403 for a package you are not allowed to see, so Gradle reports a missing token as "could not resolve io.sophonz:sophonz-android-sdk". Check the token before suspecting the version.

iOS: the Apple SDK git repository

SophonzIO is fetched with git from https://github.com/sophonz-labs/sophonz-apple-sdk.git, by CocoaPods or by SPM. The machine running pod install needs git access to that repository, through a git credential helper or ~/.netrc:

~/.netrc
machine github.com
login <your GitHub user>
password <token with repository read access>

Expo

Configure the plugin

Add the config plugin to app.json (or app.config.js):

app.json
{
  "expo": {
    "plugins": [
      [
        "@sophonz/react-native",
        {
          "androidAppKey": "sk_android_replace_me",
          "iOSAppKey": "sk_ios_replace_me",
          "iOSAppName": "my-ios-app",
          "project": "my-project",
          "deploymentEnvironment": "production"
        }
      ]
    ]
  }
}

androidAppKey and iOSAppKey are required; each platform is a separate app in the portal with its own key. The plugin is resolved from the package name; @sophonz/react-native/lib/app.plugin.js still works. Every prop is in Configuration.

If the app's Android minSdk is below 26 (Expo's default is 24), raise it with expo-build-properties, because the plugin does not add desugaring:

app.json
{
  "expo": {
    "plugins": [
      ["expo-build-properties", {"android": {"minSdkVersion": 26}}],
      ["@sophonz/react-native", {"androidAppKey": "sk_android_replace_me", "iOSAppKey": "sk_ios_replace_me"}]
    ]
  }
}

Prebuild

npx expo prebuild

The prebuild makes these changes:

PlatformChange
AndroidWrites android/app/src/main/sophonz-config.json with sdk_config.ingest and app_framework: "react_native"
AndroidAdds the GitHub Packages repository and the io.sophonz:sophonz-gradle-plugin classpath to android/build.gradle
AndroidApplies io.sophonz.gradle in android/app/build.gradle
AndroidCalls Sophonz.start(this) right after super.onCreate() in MainApplication (Kotlin or Java)
iOSWrites SophonzInitializer.swift, which starts the Apple SDK with your keys, and adds it to the Xcode project
iOSCalls SophonzInitializer.start() from the AppDelegate, adding a bridging header when the AppDelegate is Objective-C
iOSAdds the SophonzIO pod pinned to v1.0.0 and the sophonz_post_install hook to the Podfile

Then build a development build as usual (npx expo run:android, npx expo run:ios, or EAS).

CAUTION — Plugin failures are warnings

If the plugin cannot find the line it patches — an unusual MainApplication, a Podfile without post_install — prebuild still succeeds and prints a warning from @sophonz/react-native. The app then builds without the SDK. Read the prebuild output after adding the plugin.

NOTE — Generated files are not updated

sophonz-config.json and SophonzInitializer.swift are only written when they do not exist. After changing a prop, run npx expo prebuild --clean.

Because the plugin starts the SDK natively on both platforms, sdkConfig passed to initialize is ignored in an Expo app that uses it. Put options in the plugin props.

EAS Build

EAS workers need the same access as your machine.

  1. Create GITHUB_ACTOR and GITHUB_TOKEN as EAS environment variables, with secret visibility, in every environment you build. Gradle reads them directly.
  2. For iOS, write them to ~/.netrc before dependencies are installed, so pod install can clone the Apple SDK. EAS runs the eas-build-pre-install script from package.json at that point:
package.json
{
  "scripts": {
    "eas-build-pre-install": "bash eas-hooks/pre-install.sh"
  }
}
eas-hooks/pre-install.sh
#!/usr/bin/env bash
set -euo pipefail
 
if [ -n "${GITHUB_TOKEN:-}" ]; then
  printf 'machine github.com\nlogin %s\npassword %s\n' "$GITHUB_ACTOR" "$GITHUB_TOKEN" > ~/.netrc
  chmod 600 ~/.netrc
fi

Do not put the token in app.json or commit a .netrc.

Bare React Native with the wizard

From the app root, where package.json lives:

node node_modules/@sophonz/react-native/lib/scripts/setup/installAndroid.js
node node_modules/@sophonz/react-native/lib/scripts/setup/installIos.js
cd ios && pod install

Each script asks for the collector URL (leave it empty for https://in.sophonz.ai) and that platform's app key. The iOS script also asks for the iOS project folder name when it differs from package.json. Then:

ScriptStepChange
installAndroid.jspatchBuildGradleGradle plugin classpath and GitHub Packages repository in android/build.gradle
patchAppBuildGradleapply plugin: "io.sophonz.gradle" in android/app/build.gradle
createSophonzJSONandroid/app/src/main/sophonz-config.json with sdk_config.ingest
patchMainApplicationSophonz import and start in MainApplication
installIos.jsaddSophonzInitializerSwiftSophonzInitializer.swift, added to the Xcode project
iosInitializeSophonzSophonzInitializer.start() in the AppDelegate (Swift or Objective-C)
patchPodfileSophonzIO pod pinned to its git tag, and the sophonz_post_install hook

To revert both platforms:

node node_modules/@sophonz/react-native/lib/scripts/setup/uninstall.js

A Sophonz-Info.plist you added yourself is left in place.

Bare React Native by hand

Android

Add the repository and the Gradle plugin to the project build file. The repository goes in both buildscript (for the plugin) and allprojects (for the SDK artifacts).

android/build.gradle
buildscript {
  repositories {
    google()
    mavenCentral()
    maven {
      url "https://maven.pkg.github.com/sophonz-labs/sophonz-android-sdk"
      credentials {
        username = findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
        password = findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
      }
    }
  }
  dependencies {
    classpath("com.android.tools.build:gradle")
    classpath("io.sophonz:sophonz-gradle-plugin:1.0.0")
  }
}
 
allprojects {
  repositories {
    maven {
      url "https://maven.pkg.github.com/sophonz-labs/sophonz-android-sdk"
      credentials {
        username = findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
        password = findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
      }
    }
  }
}

Apply it in the app module, next to the Android application plugin:

android/app/build.gradle
apply plugin: "com.android.application"
apply plugin: "io.sophonz.gradle"

With a plugins block, use id("io.sophonz.gradle") instead. Add desugaring if minSdk is below 26.

Create the config file. The Gradle plugin compiles it into the app, so it must sit exactly here:

android/app/src/main/sophonz-config.json
{
  "sdk_config": {
    "app_framework": "react_native",
    "ingest": {
      "collector_url": "https://in.sophonz.ai",
      "service_key": "sk_android_replace_me",
      "service_namespace": "my-project"
    }
  }
}

Optionally start the SDK in MainApplication, right after super.onCreate():

MainApplication.kt
import io.sophonz.android.sophonzsdk.Sophonz
 
override fun onCreate() {
  super.onCreate()
  Sophonz.start(this)
  // ... the rest of the React Native setup
}
MainApplication.java
import io.sophonz.android.sophonzsdk.Sophonz;
 
@Override
public void onCreate() {
  super.onCreate();
  Sophonz.INSTANCE.start(this);
  // ...
}

If you skip this, initialize starts the SDK when JavaScript runs. On Android that makes no difference to configuration, which always comes from sophonz-config.json; it only moves the start later.

iOS

SophonzIO is not on the CocoaPods trunk, so the Podfile has to say where it comes from. Put the line inside the app target:

ios/Podfile
target 'MyApp' do
  pod 'SophonzIO', :git => 'https://github.com/sophonz-labs/sophonz-apple-sdk.git', :tag => 'v1.0.0'
  # ... use_react_native! and the rest
end
cd ios && pod install

Autolinking adds the React Native module pods (RNSophonzCore, and RNSophonzTracerProvider or RNSophonzOTLP when installed). The sophonz_post_install hook the wizard adds is only needed for Swift Package Manager.

You can then either start the SDK from JavaScript with sdkConfig.ios or a Sophonz-Info.plist (Configuration), or start it natively, which also captures what happens before JavaScript loads:

ios/MyApp/SophonzInitializer.swift
import Foundation
import SophonzIO
 
@objcMembers class SophonzInitializer: NSObject {
  static func start() {
    do {
      try Sophonz.start(
        options: .withCollector(
          url: "https://in.sophonz.ai",
          appKey: "sk_ios_replace_me",
          appName: "my-ios-app",
          project: "my-project",
          deploymentEnvironment: "production",
          platform: .reactNative
        )
      )
    } catch {
      print("[sophonz] failed to start: \(error)")
    }
  }
}

Call it first thing in application(_:didFinishLaunchingWithOptions:):

ios/MyApp/AppDelegate.swift
func application(
  _ application: UIApplication,
  didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
  SophonzInitializer.start()
  // ... the rest of the React Native setup
}

From an Objective-C AppDelegate.mm, import the generated Swift header and call it the same way. The header is named after the product module; the project needs a bridging header for Swift to be compiled into the target.

ios/MyApp/AppDelegate.mm
#import "AppDelegate.h"
#import "MyApp-Swift.h"
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [SophonzInitializer start];
  // ...
}

NOTE — Main thread, and .reactNative

Sophonz.start throws invalidThread anywhere but the main thread. platform: .reactNative is recorded as the app's framework resource; leave it out and the app reports as native.

New and old architecture

There is nothing to switch. On Android the module ships both a TurboModule and a legacy bridge module and Gradle picks one from the app's newArchEnabled property. On iOS the module compiles against RCT_NEW_ARCH_ENABLED. In JavaScript the package looks the module up through TurboModuleRegistry first and NativeModules second, so the same code runs on both.

If the module is not linked at all — no rebuild after installing, no pod install, or Expo Go — initialize logs a warning and resolves false, and every other call resolves its fallback value.

Initialize in JavaScript

Call initialize once, as early as possible, even when the SDK was already started natively. It installs the global error handler, records the React Native and SDK versions, and turns on unhandled promise rejection tracking.

App.tsx
import {useEffect} from "react";
import {initialize} from "@sophonz/react-native";
 
export default function App() {
  useEffect(() => {
    initialize({
      sdkConfig: {
        ios: {
          collectorUrl: "https://in.sophonz.ai",
          appKey: "sk_ios_replace_me",
        },
        trackUnhandledRejections: true,
      },
    });
  }, []);
 
  // ...
}

Or with the hook, which also tells you when it is done:

import {useSophonz} from "@sophonz/react-native";
 
const SOPHONZ_CONFIG = {
  ios: {collectorUrl: "https://in.sophonz.ai", appKey: "sk_ios_replace_me"},
  trackUnhandledRejections: true,
};
 
export default function App() {
  const {isPending, isStarted} = useSophonz(SOPHONZ_CONFIG);
  // ...
}

Define the config object outside the component: the hook re-runs when the object identity changes.

Native start or JavaScript start

initialize first asks the native SDK whether it is running.

Started nativelyStarted by initialize
Captures crashes and startup before JS loadsYesNo
sdkConfig.ios appliedNoYes
sdkConfig.exporters appliedNoYes
trackUnhandledRejections, patch appliedYesYes
Global JS error handler installedYesYes
Android configurationsophonz-config.jsonsophonz-config.json

CAUTION — A native start wins silently

If the SDK was started in MainApplication or SophonzInitializer, initialize sees it running and skips its own start, so the iOS options and exporters passed to it are dropped with no warning. Configure a natively started SDK natively: SophonzInitializer.swift or Sophonz-Info.plist on iOS, and native exporters as described in OpenTelemetry and OTLP.

Verifying

  • initialize resolves true and the console shows [Sophonz] native SDK was started (only when JavaScript did the start).
  • Throw an error from a button, or call logError("install check"), then send the app to the background. On iOS, telemetry is uploaded when a session part ends, not on a timer, so a foregrounded simulator sends nothing.
  • If the session does not appear, check the app key first. The collector drops telemetry whose key it cannot resolve without returning an error, so a wrong key looks exactly like a working install.
  • On Android, make sure the key is in android/app/src/main/sophonz-config.json of the build you installed; the value is compiled in.

Next