This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e1fe4d
commit d815162
Showing
16 changed files
with
215 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ out/ | |
local.properties | ||
**.iml | ||
*.hprof | ||
.cxx | ||
**/sentry-native-local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "sentry-android-ndk/sentry-native"] | ||
path = sentry-android-ndk/sentry-native | ||
url = https://github.com/getsentry/sentry-native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cmake_minimum_required(VERSION 3.4.1) | ||
project("sentry-android") | ||
|
||
# Adding sentry-native submodule subdirectory | ||
add_subdirectory(${SENTRY_NATIVE_SRC}) | ||
|
||
# sentry-native submodule include path. | ||
include_directories(${SENTRY_NATIVE_SRC}/include) | ||
|
||
# sentry-native source code. | ||
file(GLOB SENTRY_ANDROID_SOURCES ${CMAKE_SOURCE_DIR}/src/main/jni/*.c) | ||
|
||
# Adding dynamic library and linking it with log and sentry-native. | ||
add_library("sentry-android" SHARED ${SENTRY_ANDROID_SOURCES}) | ||
find_library(LOG_LIB log) | ||
target_link_libraries("sentry-android" "sentry" ${LOG_LIB}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
plugins { | ||
id("com.android.library") | ||
} | ||
|
||
android { | ||
compileSdkVersion(Config.Android.compileSdkVersion) | ||
buildToolsVersion(Config.Android.buildToolsVersion) | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
defaultConfig { | ||
targetSdkVersion(Config.Android.targetSdkVersion) | ||
javaCompileOptions { | ||
annotationProcessorOptions { | ||
includeCompileClasspath = true | ||
} | ||
} | ||
|
||
minSdkVersion(Config.Android.minSdkVersionNdk) | ||
externalNativeBuild { | ||
val sentryNativeSrc = if (File("${project.projectDir}/sentry-native-local").exists()) { | ||
"sentry-native-local" | ||
} else { | ||
"sentry-native" | ||
} | ||
cmake { | ||
arguments.add(0, "-DANDROID_STL=c++_static") | ||
arguments.add(0, "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON") | ||
arguments.add(0, "-DSENTRY_NATIVE_SRC=" + sentryNativeSrc) | ||
} | ||
} | ||
ndk { | ||
val platform = System.getenv("ABI") | ||
if (platform == null || platform.toLowerCase() == "all") { | ||
abiFilters("x86", "armeabi-v7a", "x86_64", "arm64-v8a") | ||
} else { | ||
abiFilters(platform) | ||
} | ||
} | ||
|
||
missingDimensionStrategy(Config.Flavors.dimension, Config.Flavors.production) | ||
} | ||
|
||
externalNativeBuild { | ||
cmake { | ||
setPath("CMakeLists.txt") | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
api(project(":sentry-core")) | ||
api(project(":sentry-android-core")) | ||
} | ||
|
||
val initNative = tasks.register<Exec>("initNative") { | ||
logger.log(LogLevel.LIFECYCLE, "Initializing git submodules") | ||
commandLine("git", "submodule", "update", "--init", "--recursive") | ||
} | ||
|
||
tasks.named("preBuild") { | ||
dependsOn(initNative) | ||
} |
Submodule sentry-native
added at
03b86e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="io.sentry.android.ndk" /> |
24 changes: 24 additions & 0 deletions
24
sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.sentry.android.ndk; | ||
|
||
import io.sentry.core.SentryOptions; | ||
|
||
public class SentryNdk { | ||
static { | ||
System.loadLibrary("sentry"); | ||
} | ||
|
||
static { | ||
System.loadLibrary("sentry-android"); | ||
} | ||
|
||
private static native void initSentryNative(String cacheDirPath); | ||
|
||
public static void notifyNewSerializedEnvelope(String path) { | ||
System.out.println("envelope written to " + path); | ||
} | ||
|
||
public static void init(SentryOptions options, String cacheDirPath) { | ||
// Java_example | ||
initSentryNative(cacheDirPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <string.h> | ||
#include <sentry.h> | ||
#include <jni.h> | ||
#include <malloc.h> | ||
#include <android/log.h> | ||
|
||
struct transport_options { | ||
jmethodID notify_envelope_mid; | ||
jclass cls; | ||
JNIEnv *env; | ||
char event_path[4096]; | ||
}; | ||
|
||
struct transport_options g_transport_options; | ||
|
||
static void send_envelope(const sentry_envelope_t *envelope, void *data) { | ||
char event_path[4096]; | ||
strcpy(event_path, g_transport_options.event_path); | ||
strcat(event_path, "/test.envelope"); | ||
sentry_envelope_write_to_file(envelope, event_path); | ||
jstring jevent_path = (*g_transport_options.env)->NewStringUTF(g_transport_options.env, event_path); | ||
(*g_transport_options.env)->CallStaticVoidMethod(g_transport_options.env, g_transport_options.cls, g_transport_options.notify_envelope_mid, jevent_path); | ||
} | ||
|
||
JNIEXPORT void JNICALL Java_io_sentry_android_ndk_SentryNdk_initSentryNative(JNIEnv *env, jclass cls, jstring cache_dir_path) { | ||
const char *path = (*env)->GetStringUTFChars(env, cache_dir_path, 0); | ||
strcpy(g_transport_options.event_path, path); | ||
g_transport_options.env = env; | ||
g_transport_options.cls = cls; | ||
g_transport_options.notify_envelope_mid = (*env)->GetStaticMethodID(env, cls, "notifyNewSerializedEnvelope", "(Ljava/lang/String;)V"); | ||
|
||
sentry_options_t *options = sentry_options_new(); | ||
|
||
sentry_options_set_transport(options, send_envelope, NULL); | ||
|
||
sentry_options_set_environment(options, "Production"); | ||
sentry_options_set_release(options, "5fd7a6cd"); | ||
sentry_options_set_debug(options, 1); | ||
sentry_options_set_dsn(options, "http://dfbecfd398754c73b6e8104538e89124@sentry.io/1322857"); | ||
|
||
sentry_init(options); | ||
|
||
sentry_value_t event = sentry_value_new_event(); | ||
sentry_value_set_by_key(event, "message", | ||
sentry_value_new_string("Hello World!")); | ||
|
||
sentry_capture_event(event); | ||
|
||
sentry_shutdown(); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
rootProject.name = "sentry" | ||
rootProject.buildFileName = "build.gradle.kts" | ||
|
||
include("sentry-android", "sentry-android-core", "sentry-core", "sentry-sample") | ||
include("sentry-android", "sentry-android-ndk", "sentry-android-core", "sentry-core", "sentry-sample") |