BugSnag is now Insight Hub – we're making some changes to how the product looks, but this won't impact the way you use BugSnag or any of your integrations.

Native API configuration

The BugSnag NDK API is a collection of C and C++ helpers that allow you to report handled errors, leave breadcrumbs and set user information.

Our native library is packaged in the bugsnag-plugin-android-ndk module of the BugSnag Android SDK and is installed as part of the Integration Guide to automatically report native crashes. The following steps are only required if you have native C/C++ code from which you wish to call the native BugSnag API.

Configuration

Since v6 of our SDK, the library is packaged as a Prefab to make configuration straightforward.

Ensure prefab is enabled and add the BugSnag NDK library to your pickFirsts:

buildFeatures.prefab = true
packagingOptions.jniLibs.pickFirsts.add("**/libbugsnag-ndk.so")
buildFeatures.prefab = true
packagingOptions.jniLibs.pickFirsts += ["**/libbugsnag-ndk.so"]

Then update your CMakeLists.txt file to reference the library:

find_package(bugsnag-plugin-android-ndk REQUIRED CONFIG)

target_link_libraries(entrypoint bugsnag-plugin-android-ndk::bugsnag-ndk)

Legacy extraction

The BugSnag Gradle plugin can be used to extract the library and header files with the enableLegacyNativeExtraction configuration option. The libraries can then be linked with the following in your makefile:

add_library(lib_bugsnag SHARED IMPORTED)

# Edit the relative path based on your CMakeLists.txt location
set(BUGSNAG_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../build/intermediates/bugsnag-libs)

set(BUGSNAG_INCLUDE_DIR ${BUGSNAG_LIB_DIR}/prefab/modules/bugsnag-ndk/include)
# In bugsnag-android v5.x and earlier, the path was:
# set(BUGSNAG_INCLUDE_DIR ${BUGSNAG_LIB_DIR}/assets/include)

set_target_properties(lib_bugsnag PROPERTIES IMPORTED_LOCATION 
                      ${BUGSNAG_LIB_DIR}/jni/${ANDROID_ABI}/libbugsnag-ndk.so)

# Insert your target name:
target_include_directories(your-native-lib PRIVATE ${BUGSNAG_INCLUDE_DIR})
target_link_libraries(your-native-lib lib_bugsnag)

Usage

Once you have added our library and header files to your build, you can include the bugsnag.h header file to invoke BugSnag functions for reporting handled errors, leaving breadcrumbs, and setting user information. User information and breadcrumbs will be attached to all subsequent error reports from Java, Kotlin and C/C++.

The syntax for these functions are given alongside the Java/Kotlin snippets where available.