Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions docs/platforms/android/configuration/using-ndk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The Android Native Development Kit (NDK) allows you to implement parts of your a

NDK integration is packed with the SDK. The package `sentry-android-ndk` works by bundling Sentry's native SDK, [`sentry-native`](/platforms/native/). As a result, even if a native library in your app causes the crash, Sentry is able to capture it.

You can [disable the NDK integration](#disable-ndk-integration), use our Sentry Android SDK [without the NDK](#using-the-sdk-without-the-ndk).
You can [disable the NDK integration](#disable-ndk-integration), or use our Sentry Android SDK [without the NDK](#using-the-sdk-without-the-ndk).

## Symbolicate Stack Traces

Expand All @@ -21,39 +21,39 @@ Please check the full documentation on [uploading files](/platforms/android/data

## Allowing the Compiler to Link Libraries

To use the Android NDK in your native code, include the Sentry NDK libraries into your project so that the compiler can link the libraries during the build.
To use the Android NDK in your native code, include the `sentry-native` NDK libraries so the compiler can link them during the build. Use Android prefab to consume Sentry's prebuilt packages and link them in your `CMakeLists.txt`.

To do so, use the AndroidNativeBundle Gradle plugin that copies the native libraries from the Sentry NDK into the location that can provide links via the `CmakeLists.txt` configuration file.
<Alert>

First, we need to declare the dependency in the project build.gradle file:
Android prefab support can only be used with Sentry Android SDK version 8.0.0 and above.

```groovy {filename:build.gradle}
buildscript {
repositories {
mavenCentral()
}
</Alert>

Enable prefab and add the sentry-native ndk dependency directly to your module:

dependencies {
// Add the line below, the plugin that copies the binaries
// https://github.com/howardpang/androidNativeBundle/releases
classpath 'io.github.howardpang:androidNativeBundle:{version}'
```kotlin {filename:app/build.gradle}
android {
buildFeatures {
prefab = true
}
}
```

Once the dependency is declared, you can use it in the application `build.gradle`:

```groovy
apply plugin: 'com.ydq.android.gradle.native-aar.import'
dependencies {
// The version MUST match with the version the Sentry Android SDK is using.
// See https://github.com/getsentry/sentry-java/blob/{{@inject packages.version('sentry.java.android', '8.21.1') }}/gradle/libs.versions.toml
implementation("io.sentry:sentry-native-ndk:<version>")
}
```

Then update the `CmakeLists.txt` configuration to link the Sentry NDK libraries:
Link the pre-built packages with your native code

```
# include paths generated by androidNativeBundle
include (${ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK})
# change native-lib to your native lib's name
target_link_libraries(native-lib ${ANDROID_GRADLE_NATIVE_MODULES})
```text {filename:app/CMakeLists.txt}
find_package(sentry-native-ndk REQUIRED CONFIG)

target_link_libraries(<app> PRIVATE
sentry-native-ndk::sentry-android
sentry-native-ndk::sentry
)
```

Now you can use the Sentry NDK API just by including the `sentry.h` in your code:
Expand Down
Loading