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. User information and breadcrumbs will be attached to all subsequent error reports from Java, Kotlin and C/C++.

Configuration

The native BugSnag library is packaged as part of the BugSnag Android SDK and is installed as per our Integration guide. The following configuration is required to allow you to link against it in your app.

Once complete, you can include bugsnag.h header file to invoke BugSnag functions for reporting handled errors, leaving breadcrumbs, and setting user information. The syntax for these functions are given alongside the Java/Kotlin snippets were available.

Using Prefab

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)

Using our Gradle plugins

If you are using the BugSnag Android Gradle plugin, the library and header files will be extracted automatically to ${CMAKE_SOURCE_DIR}/build/intermediates/bugsnag-libs during a build.

With our newer BugSnag Gradle plugin, you can enable the enableLegacyNativeExtraction configuration option to provide the same behavior.

The libraries can then be linked with the following in your makefile:

add_library(lib_bugsnag SHARED IMPORTED)
# This directory is created automatically by the BugSnag Gradle plugin
set(BUGSNAG_LIB_DIR
    ${CMAKE_SOURCE_DIR}/build/intermediates/bugsnag-libs)
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)