Upload source maps for React Native Android builds

To get unminified stack traces for JavaScript code in your React Native app built for Android, source maps must be generated and uploaded to BugSnag.

For installation instructions for the BugSnag CLI, please see our Installation guide.

Overview

The react-native-android command uploads the bundled JavaScript and source maps generated during a release build and uploads it to the React Native source map API.

In addition to the source maps, the command extracts version and build information, including your BugSnag API key, required for the upload from your app’s manifest file (AndroidManifest.xml). These values can be overridden, or provided entirely, by command line options.

Example usage

The simplest way to run the command is from the root directory of your React Native project:

$ bugsnag-cli upload react-native-android

Or by providing a specific bundle file and associated mapping file to upload:

$ bugsnag-cli upload react-native-android \
    --bundle android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle \
    --source-map android/app/build/generated/sourcemaps/react/release/index.android.bundle.map

If your build contains multiple variants or has a non-standard project layout, you might need to provide extra options:

$ bugsnag-cli upload react-native-android \
    --app-manifest android/app/build/intermediates/merged_manifests/release/AndroidManifest.xml \
    --variant release

Available options

API key (--api-key)

The BugSnag API key for the application.

You can find your API key in Project Settings from your BugSnag dashboard.

Default: the value of com.bugsnag.android.API_KEY in your app’s manifest file, if found.

App manifest (--app-manifest)

The path to a manifest file (AndroidManifest.xml) from which to obtain build information.

Default: android/app/build/intermediates/merged_manifests/<variant>/AndroidManifest.xml from your project directory. .

Bundle (--bundle)

The path to the bundled JavaScript file to upload.

Default: android/app/build/generated/sourcemaps/react/release/index.android.bundle.map from your project directory. .

Code bundle id (--code-bundle-id)

A unique identifier for the JavaScript bundle.

If you use CodePush, or similar mechanism, to update the JavaScript bundle of your app without changing the native version or build number, use the code bundle ID to uniquely identify the update. This same ID must also be set in the BugSnag configuration in your app, so that errors match the uploaded bundle.

Dev (--dev)

Indicates whether this is a debug or release build.

Dry run (--dry-run)

Performs a dry-run of the command without sending any information to BugSnag.

Fail on upload error (--fail-on-upload-error)

Stops the upload when a file fails to upload successfully.

Log level (--log-level)

Sets the level of logging to debug, info, warn or fatal.

Default: info.

Overwrite (--overwrite)

Whether to ignore and overwrite existing uploads with same identifier, rather than failing if a matching file exists.

Port (--port)

The port number for the BugSnag upload server.

Default: 443.

Project root (--project-root)

The path to strip from the beginning of source file names referenced in stacktraces on the BugSnag dashboard.

Default: the root directory if the command has detected one, otherwise it’s empty.

Retries (--retries)

The number of retry attempts before failing an upload request.

Default: 0.

Source map (--source-map)

The path to the source map file to upload.

Default: android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle from your project directory. .

Timeout (--timeout)

The number of seconds to wait before failing an upload request.

Default: 300.

Upload API root URL (--upload-api-root-url)

The upload server hostname, optionally containing port number.

For use in BugSnag On-premise configurations. The command will append the appropriate path to access the correct upload endpoint.

Default: https://upload.bugsnag.com.

Variant (--variant)

The build type/flavor (e.g. debug, release) used to disambiguate the between built files when searching the project directory.

Verbose (--verbose)

Sets the level of the logging to its highest.

This is the equivalent of setting the log level to debug.

Version code (--version-code)

The version code of this build of the application.

Default: the value of VersionCode in your app’s manifest file, if found.

Version name (--version-name)

The version of the application.

Default: the value of VersionName in your app’s manifest file, if found.