Skip to content

Commit

Permalink
Move NDK from sentry-java to sentry-native (#944)
Browse files Browse the repository at this point in the history
* Added initial poc

* Re-structure package names to NDK

* Post PoC cleanup

* setup module name for prefab

* Prepare for publishing

* Switch to shared STL instead of static

* Wire ndk artifact generation with github actions

* Fix distDir

* Update Changelog

* Setup Java/Gradle for CI

* Update READMEs

* Fix typos

* Build libraries with c++_shared to comply with prefab

* Address PR feedback
  • Loading branch information
markushi authored May 22, 2024
1 parent 97b9c76 commit 6544650
Show file tree
Hide file tree
Showing 38 changed files with 2,574 additions and 9 deletions.
10 changes: 10 additions & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ targets:
- name: registry
sdks:
github:getsentry/sentry-native:
maven:io.sentry:sentry-native-ndk:
- name: gcs
bucket: sentry-sdk-assets
paths:
Expand All @@ -14,5 +15,14 @@ targets:
- path: /sentry-native/latest/
metadata:
cacheControl: public, max-age=600
- name: maven
mavenCliPath: scripts/mvnw
mavenSettingsPath: scripts/settings.xml
mavenRepoId: ossrh
mavenRepoUrl: https://oss.sonatype.org/service/local/staging/deploy/maven2/
android:
distDirRegex: /^(sentry-native-ndk).*$/
fileReplaceeRegex: /\d+\.\d+\.\d+(-\w+(\.\d+)?)?(-SNAPSHOT)?/
fileReplacerStr: release.aar
requireNames:
- /^sentry-native.zip$/
32 changes: 24 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ jobs:
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
python-version: "3.11"
cache: "pip"

- name: Installing Linux Dependencies
if: ${{ runner.os == 'Linux' && !env['TEST_X86'] }}
Expand All @@ -149,7 +149,7 @@ jobs:
- name: Expose llvm PATH for Mac
if: ${{ runner.os == 'macOS' }}
run: echo $(brew --prefix llvm@15)/bin >> $GITHUB_PATH

- name: Installing LLVM-MINGW Dependencies
if: ${{ runner.os == 'Windows' && env['TEST_MINGW'] }}
shell: powershell
Expand Down Expand Up @@ -203,15 +203,31 @@ jobs:
with:
submodules: recursive

- name: Setup Java Version
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"

- name: Setup Gradle
uses: gradle/actions/setup-gradle@579fbbe7221704325eb4c4d4bf20c2b0859fba76 # pin@v3
with:
gradle-home-cache-cleanup: true

- name: Create source archive
run: |
rm -rf build .c* .e* .git* scripts Makefile external/breakpad/src/tools external/breakpad/src/processor
zip -r sentry-native.zip .
- name: Upload source artifact
uses: actions/upload-artifact@v3
- name: Build NDK artifacts
working-directory: ndk
run: ./gradlew clean distZip

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ github.sha }}
# When downloading artifacts, they are double-zipped:
# https://github.com/actions/upload-artifact#zipped-artifact-downloads
path: sentry-native.zip
if-no-files-found: error
path: |
./*/build/distributions/*.zip
sentry-native.zip
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ CodeChecker

# Coverage
coverage

# Gradle / Java
local.properties
.gradle
.cxx
build

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

- Add compile-time flag `SENTRY_TRANSPORT_COMPRESSION` description to the `README.md` file. ([#976](https://github.com/getsentry/sentry-native/pull/976))

**Internal**:

- Move sentry-android-ndk JNI related parts from sentry-java to sentry-native ([#944](https://github.com/getsentry/sentry-native/pull/944))
This will create a pre-built `io.sentry:sentry-native-ndk` maven artifact, suitable for being consumed by Android apps.

**Thank you**:

- [@AenBleidd](https://github.com/AenBleidd)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The SDK bundle contains the following folders:
directory or copy the header file to your source tree so that it is available
during the build.
- `src`: Sources of the Sentry SDK required for building.
- `ndk`: Sources for the Android NDK JNI layer.

## Platform and Feature Support

Expand Down Expand Up @@ -122,11 +123,14 @@ Please refer to the CMake Manual for more details.
**Android**:

The CMake project can also be configured to correctly work with the Android NDK,
see the dedicated [CMake Guide] for details on how to integrate it with gradle
see the dedicated [CMake Guide] for details on how to integrate it with Gradle
or use it on the command line.

The `ndk` folder provides Gradle project which adds a Java JNI layer for Android, suitable for accessing the sentry-native SDK from Java. See the [NDK Readme] for more details about this topic.

[cmake]: https://cmake.org/cmake/help/latest/
[cmake guide]: https://developer.android.com/ndk/guides/cmake
[NDK Readme]: ndk/README.md

**MinGW**:

Expand Down
75 changes: 75 additions & 0 deletions ndk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Android NDK support for sentry-native

| Package | Maven Central | Minimum Android API Level | Supported ABIs |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- | ------------------------------------------- |
| `io.sentry:sentry-native-ndk` | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-native-ndk/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.sentry/sentry-native-ndk) | 19 | "x86", "armeabi-v7a", "x86_64", "arm64-v8a" |

## Resources

- [SDK Documentation](https://docs.sentry.io/platforms/native/)
- [Discord](https://discord.gg/ez5KZN7) server for project discussions
- Follow [@getsentry](https://twitter.com/getsentry) on Twitter for updates

## About

The sub-project aims to automatically bundle pre-built `sentry-native` binaries together with a Java JNI layer into an Android friendly `.aar` package.

The `.aar` package also provides [prefab](https://developer.android.com/build/native-dependencies?buildsystem=cmake) support, giving you the possibility to consume the native `sentry.h` APIs from your native app code.

If you're using the [Sentry Android SDK](https://docs.sentry.io/platforms/android/), this package is included by default already.

Besides the main package in `ndk/lib`, a simple Android app for for testing purposes is provided in the `ndk/sample` folder.

## Building and Installation

The `ndk` project uses the Gradle build system in combination with CMake. You can either use a suitable IDE (e.g. Android Studio) or the command line to build it.

## Testing and consuming a local package version

1. Set a custom `versionName` in the `ndk/gradle.properties` file
2. Publish the package locally

```shell
cd ndk
./gradlew :sentry-native-ndk:publishToMavenLocal
```

3. Consume the build in your app

```
// usually settings.gradle
allprojects {
repositories {
mavenLocal()
}
}
// usually app/build.gradle
android {
buildFeatures {
prefab = true
}
}
dependencies {
implementation("io.sentry:sentry-native-ndk:<version>")
}
```

4. Link the pre-built packages with your native code

```cmake
# usually app/CMakeLists.txt
find_package(sentry-native-ndk REQUIRED CONFIG)
target_link_libraries(<app> PRIVATE
${LOG_LIB}
sentry-native-ndk::sentry-android
sentry-native-ndk::sentry
)
```

## Development

Please see the [contribution guide](../CONTRIBUTING.md).
Loading

0 comments on commit 6544650

Please sign in to comment.