React Native SDK

React NativeAndroidiOS

The Snapbug React Native SDK provides JavaScript bindings to the native Snapbug SDK, enabling network interception, analytics monitoring, crash reporting, and live logs from your React Native app.

Requirements

  • React Native >= 0.73.0
  • React >= 18.0.0
  • Android minSdk 24, plus the Android toolchain floor below
  • iOS >= 15.0 (Apple-silicon simulators or physical devices)

Android toolchain floor

The SDK's Android artifacts need a recent build toolchain. Older project templates (for example React Native 0.73) ship below it and fail to build until it is raised:

WhatMinimumWhere
compileSdk36android/app/build.gradle
Android Gradle plugin8.6.0android/settings.gradle(.kts) (com.android.application) or android/build.gradle
Gradle wrapper8.7android/gradle/wrapper/gradle-wrapper.properties
Kotlin Gradle plugin2.2org.jetbrains.kotlin.android next to AGP, or the kotlinVersion / kotlin_version property

Raise only what is below the minimum, and never lower anything. If android/build.gradle sets minSdkVersion below 24, raise it to 24.

Installation

Let your AI coding agent do this integration for you — see Install with an AI agent.

npm install snapbug-react-native

The package has its own version number, separate from the native SDK it brings: the current npm release is 0.1.0 while the pods and Maven artifacts it brings are 0.1.1. That is expected; let npm choose the package version. Do not edit MainActivity, MainApplication or AppDelegate, and do not add ai.snapbug:* Gradle dependencies: on Android the module already wires the debug SDK and the release no-op twin.

For iOS, install the native pods — the SDK arrives as the published Snapbug pod from CocoaPods trunk:

cd ios && bundle exec pod install

Use plain pod install if the project has no Gemfile. The first run also creates or updates Xcode project files; commit them.

Known issue in SDK 0.1.1: the current snapbug-react-native release on npm brings SDK 0.1.1 on Android, which points the app at @xml/network_security_config but does not ship that file. A debug build then fails with resource xml/network_security_config ... not found. Unless android/app/src/main/AndroidManifest.xml already sets its own android:networkSecurityConfig, create android/app/src/debug/res/xml/network_security_config.xml with the content below.

<?xml version="1.0" encoding="utf-8"?>
<!-- Needed by Snapbug SDK 0.1.1 in debug builds; delete after upgrading Snapbug. -->
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">127.0.0.1</domain>
    </domain-config>
</network-security-config>

Release builds on iOS

On Android the release twin is wired in automatically. CocoaPods has no equivalent mechanism, so add two lines to your app's ios/Podfile, inside the app target (for example right after config = use_native_modules!), then run bundle exec pod install again:

# inside your app target
pod 'Snapbug',       '~> 1.0.4', :configurations => ['Debug']
pod 'Snapbug-no-op', '~> 1.0.4', :configurations => ['Release']

The platform must be at least iOS 15. Templates from React Native 0.76 on use platform :ios, min_ios_version_supported, which is already 15.1, so leave that line alone; older templates need platform :ios, '15.0'. Both pods provide a module named Snapbug, so the warning 'Snapbug' is missing a dependency on 'Snapbug-no-op' is expected and harmless.

Snapbug-no-op exposes the same API with every call inert. The native module compiles against it unchanged, and your App Store build carries neither the inspector nor the overlay — Snapbug.framework drops from 31 MB to 6.7 MB, while Debug keeps the live SDK. See iOS SDK → Release builds.

Quick Start

No native code required. Snapbug.start() from JS boots the native SDK through the module — nothing goes in MainActivity or AppDelegate.

import { Snapbug, patchFetch } from 'snapbug-react-native';
 
// Patch fetch for automatic network interception
patchFetch();
 
Snapbug.start();

Put this in the JS entry file (index.js / index.ts, the one that calls AppRegistry.registerComponent), at the top after the imports and before the registration: patchFetch() must run before any module makes a request.

Settings go through the same call:

Snapbug.start({
  serverHost: '192.168.1.42',  // LAN IP of your Mac for physical devices; not needed for simulators or relay
  overlay: 'BUBBLE',           // Android only: BUBBLE (default), FAB or NONE
  appVersion: '1.0.0',
});

If you start the native SDK yourself

Only needed when you want native configuration with no JS equivalent — declaring your app's own deep links, for instance. Snapbug.start() then sees the running SDK and just attaches the JS plugins to the bridge.

The module declares the SDK as implementation, so the classes exist at runtime but are not on your app's compile classpath. For your own call, add exactly this pair to android/app/build.gradle:

dependencies {
    debugImplementation("ai.snapbug:snapbug:1.0.4")
    releaseImplementation("ai.snapbug:snapbug-no-op:1.0.4")
}

Both artifacts expose every plugin through api. Do not add the per-plugin artifacts (snapbug-analytics, snapbug-device, snapbug-transport-webrtc-no-op, …) — in release they land next to their no-op twins and the build fails on Duplicate class.

Snapbug.start takes an Activity, which it needs for the overlay, so this does not go in MainApplication:

import io.snapbug.sdk.OverlayMode
import io.snapbug.sdk.Snapbug
import io.snapbug.sdk.start
 
class MainActivity : ReactActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Snapbug.start(this) {
            overlay = OverlayMode.BUBBLE
            deeplinks { deeplink("myapp://product", label = "Open product") }
        }
    }
}

Logs

Log lines stream into the Logs inspector in real time:

  • Android — the native SDK captures logcat; console.log from JS lands there under the ReactNativeJS tag, so nothing extra is needed.
  • iOS — the RN engine routes console.* to os_log, past stdout, so the SnapbugLogs JS plugin (part of the default plugin set) hooks console.log/info/warn/error/debug and forwards each line (log/info → I, debug → D, warn → W, error → E).

Network Inspection

Automatic Fetch Interception

The SDK can automatically intercept all fetch calls by patching the global fetch function:

import { patchFetch, unpatchFetch } from 'snapbug-react-native';
 
// Start intercepting
patchFetch();
 
// All fetch() calls are now captured
const response = await fetch('https://api.example.com/users');
 
// Stop intercepting when no longer needed
unpatchFetch();

Only fetch is patched. axios uses XMLHttpRequest by default, so its calls do not appear in the network tab unless you set adapter: 'fetch'.

Manual Logging

For custom HTTP clients, send protocol messages directly. sendMessage takes the plugin ID, method name, and a JSON string body:

import { Snapbug } from 'snapbug-react-native';
 
Snapbug.sendMessage(
  'network',
  'logNetworkCallRequest',
  JSON.stringify({
    snapbugCallId: 'my-call-1',
    snapbugNetworkType: 'HTTP',
    url: 'https://api.example.com/users',
    method: 'POST',
    startTime: Date.now(),
    requestHeaders: { 'Content-Type': 'application/json' },
    requestBody: JSON.stringify({ name: 'John' }),
  })
);

Analytics

Log analytics events with a table identifier:

import { Snapbug } from 'snapbug-react-native';
 
Snapbug.analytics('firebase').logEvents([
  {
    eventName: 'screen_view',
    properties: { screen_name: 'Home' },
  },
  {
    eventName: 'button_click',
    properties: { button_id: 'sign_up' },
  },
]);

Crash Reporter

Automatic Fatal Error Capture

Enable fatal error capture when starting the SDK:

import { Snapbug, SnapbugCrashReporter, SnapbugNetwork, SnapbugAnalytics, SnapbugLogs } from 'snapbug-react-native';
 
Snapbug.start({
  plugins: [
    new SnapbugNetwork(),
    new SnapbugAnalytics(),
    new SnapbugCrashReporter({ catchFatalErrors: true }),
    new SnapbugLogs(),
  ],
});

Manual Error Reporting

Report caught exceptions:

import { SnapbugCrashReporter } from 'snapbug-react-native';
 
try {
  await riskyOperation();
} catch (error) {
  SnapbugCrashReporter.reportError(error);
}

API Reference

MethodDescription
Snapbug.start(config?)Initialize the JS bridge; pass { plugins: [...] } to enable a subset
Snapbug.stop()Disconnect and stop all JS plugins
Snapbug.analytics(tableId)Get an analytics builder for the given table
Snapbug.getPlugin(PluginClass)Get a plugin instance by class
Snapbug.sendMessage(plugin, method, body)Send a raw protocol message (body is a JSON string)
Snapbug.updateServerHost(host)Change the inspector host address (for Wi-Fi connections)
patchFetch()Patch global fetch for automatic network interception
unpatchFetch()Restore the original fetch function
new SnapbugCrashReporter({ catchFatalErrors })Crash reporter plugin; captures unhandled JS errors when enabled
SnapbugCrashReporter.reportError(error, stackTrace?)Report a caught error manually

Example App

A complete React Native example app is available at samples/react-native/ in the repository.

To run it:

cd samples/react-native
npm install
npm run android

For iOS:

cd samples/react-native
npm install
cd ios && pod install && cd ..
npm run ios

Next Steps