Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
858e35a
plug in sentry-native
bruno-garcia Oct 3, 2019
bca5858
Merge branch 'master' of github.com:getsentry/sentry-android into fea…
bruno-garcia Oct 7, 2019
f775e74
fix: lib name
bruno-garcia Oct 8, 2019
62dc8ff
feat: Link with sentry-native
tonyo Oct 8, 2019
80c1630
Update sentry-android-ndk/build.gradle.kts
bruno-garcia Oct 9, 2019
39cc3f4
ref: self close tag
bruno-garcia Oct 9, 2019
0e8cec2
ref: fix symlink
mitsuhiko Oct 9, 2019
bd46263
ref: Fixed the print callback
mitsuhiko Oct 10, 2019
25081a8
Update sentry-android-ndk/CMakeLists.txt
bruno-garcia Oct 12, 2019
b50fdab
Merge branch 'master' of github.com:getsentry/sentry-android into fea…
bruno-garcia Oct 14, 2019
dbc9c11
fix: Rely on permission defined in SDK
bruno-garcia Oct 14, 2019
f623c99
Update sentry-android-ndk/CMakeLists.txt
bruno-garcia Oct 14, 2019
2a1e1e0
Update sentry-android-ndk/CMakeLists.txt
bruno-garcia Oct 14, 2019
6a8635a
Update sentry-android-ndk/CMakeLists.txt
bruno-garcia Oct 14, 2019
68a2047
feat: Init SentryNdk when available
bruno-garcia Oct 14, 2019
40fd845
Merge branch 'master' of github.com:getsentry/sentry-android into fea…
bruno-garcia Oct 14, 2019
eba52d1
Merge branch 'feat/ndk' of github.com:getsentry/sentry-android into f…
bruno-garcia Oct 15, 2019
0b682d0
fix merge conflict
Oct 18, 2019
8b0d497
feat: Some ugly code to do something
mitsuhiko Oct 22, 2019
ce4e004
lint
bruno-garcia Oct 22, 2019
63efb43
Merge branch 'master' of github.com:getsentry/sentry-android into fea…
bruno-garcia Oct 22, 2019
12e6b9f
ref: remove symlink
bruno-garcia Oct 22, 2019
afbb473
feat: sentry-native submodule ndk branch
bruno-garcia Oct 22, 2019
e0bcee9
feat(ndk): Specify SENTRY_NATIVE_SRC in build.gradle
tonyo Oct 22, 2019
8c62844
try: Conditional sentry-native usage
tonyo Oct 22, 2019
5f8e145
feat: Use submodule or local override
bruno-garcia Oct 22, 2019
d11b2b7
ref: set compat version
bruno-garcia Oct 22, 2019
5fa906a
feat: Build NDK only for specific platforms if ABI is set
tonyo Oct 23, 2019
0f1fa04
fix: target of the symbolic link is taken literally from the first ar…
bruno-garcia Oct 23, 2019
6331600
Update README.md
bruno-garcia Oct 23, 2019
51c439e
Update README.md
bruno-garcia Oct 23, 2019
95b7f18
Merge branch 'master' into feat/ndk-submodule
bruno-garcia Oct 23, 2019
d779142
ref: API 14 doesn't support multi catch exception
bruno-garcia Oct 23, 2019
5f43c79
feat: Use API 14
bruno-garcia Oct 23, 2019
adc8f19
Merge branch 'master' of github.com:getsentry/sentry-android into fea…
bruno-garcia Oct 23, 2019
8c9ea4d
ref: Use const for version
bruno-garcia Oct 23, 2019
9e03b27
ref: Fix linter
bruno-garcia Oct 23, 2019
88c0285
ref: meta-package requires highest API lvl
bruno-garcia Oct 23, 2019
3613ee2
Merge branch 'master' of github.com:getsentry/sentry-android into fea…
bruno-garcia Oct 23, 2019
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ out/
local.properties
**.iml
*.hprof
.cxx
sentry-native-local/
**/sentry-native-local
3 changes: 3 additions & 0 deletions .gitmodules
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ Android SDK for Sentry
[![AppVeyor](https://ci.appveyor.com/api/projects/status/kr49snupeb1dsgwa/branch/master?svg=true)](https://ci.appveyor.com/project/sentry/sentry-android/branch/master)
[![Tests](https://img.shields.io/appveyor/tests/sentry/sentry-android/master?compact_message)](https://ci.appveyor.com/project/sentry/sentry-android/branch/master/tests)
[![codecov](https://codecov.io/gh/getsentry/sentry-android/branch/master/graph/badge.svg)](https://codecov.io/gh/getsentry/sentry-android)

# Development

This repository includes [`sentry-native`](https://github.com/getsentry/sentry-native/) as a git submodule.
To build against `sentry-native` checked-out elsewhere in your file system, create a symlink to `sentry-android-ndk/sentry-native-local`.
For example, if you had `sentry-native` checked-out in a sibling directory to this repo:

`ln -s ../sentry-native sentry-android-ndk/sentry-native-local`

which will be picked up by `gradle` and used instead of the git submodule.
This directory is algo included in `.gitignore` not to be shown as pending changes.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ allprojects {
TestLogEvent.FAILED)
dependsOn("cleanTest")
}
withType<JavaCompile> {
options.compilerArgs.addAll(arrayOf("-Xlint:all", "-Werror", "-Xlint:-classfile"))
}
// withType<JavaCompile> {
// options.compilerArgs.addAll(arrayOf("-Xlint:all", "-Werror", "-Xlint:-classfile"))
// }
}
}

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Config {
private val sdkVersion = 29

val buildToolsVersion = "29.0.2"
val minSdkVersion = 14
val minSdkVersion = 21
val minSdkVersionDebug = 21
val targetSdkVersion = sdkVersion
val compileSdkVersion = sdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import android.content.Context;
import io.sentry.core.ILogger;
import io.sentry.core.SentryLevel;
import io.sentry.core.SentryOptions;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

class AndroidOptionsInitializer {
static void init(SentryOptions options, Context context) {
Expand All @@ -15,8 +19,30 @@ static void init(SentryOptions options, Context context, ILogger logger) {

// TODO this needs to fetch the data from somewhere - defined at build time?
options.setSentryClientName("sentry-android/0.0.1");

ManifestMetadataReader.applyMetadata(context, options);

if (options.isEnableNdk()) {
try {
// TODO: Create Integrations interface and use that to initialize NDK
Class cls = Class.forName("io.sentry.android.ndk.SentryNdk");

// TODO: temporary hack
String cacheDirPath = context.getCacheDir().getAbsolutePath() + "/sentry-envelopes";
File f = new File(cacheDirPath);
f.mkdirs();

Method method = cls.getMethod("init", SentryOptions.class, String.class);
Object[] args = new Object[2];
args[0] = options;
args[1] = cacheDirPath;
method.invoke(null, args);
} catch (ClassNotFoundException exc) {
options.getLogger().log(SentryLevel.ERROR, "Failed to load SentryNdk.");
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
options.getLogger().log(SentryLevel.ERROR, "Failed to initialize SentryNdk.", e);
}
}

options.addEventProcessor(new DefaultAndroidEventProcessor(context, options));
options.setSerializer(new AndroidSerializer(options.getLogger()));
}
Expand Down
16 changes: 16 additions & 0 deletions sentry-android-ndk/CMakeLists.txt
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})
60 changes: 60 additions & 0 deletions sentry-android-ndk/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

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(21)
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 {
abiFilters("x86", "armeabi-v7a", "x86_64", "arm64-v8a")
}

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)
}
1 change: 1 addition & 0 deletions sentry-android-ndk/sentry-native
Submodule sentry-native added at 03b86e
2 changes: 2 additions & 0 deletions sentry-android-ndk/src/main/AndroidManifest.xml
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" />
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);
}
}
52 changes: 52 additions & 0 deletions sentry-android-ndk/src/main/jni/sentry.c
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://[email protected]/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();

}

2 changes: 1 addition & 1 deletion sentry-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ android {

dependencies {
api(project(":sentry-android-core"))
// TODO: Add NDK: api(project(":sentry-android-ndk"))
api(project(":sentry-android-ndk"))
}
9 changes: 9 additions & 0 deletions sentry-core/src/main/java/io/sentry/core/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class SentryOptions {
private String dsn;
private long shutdownTimeoutMills;
private boolean debug;
private boolean enableNdk = true;
private @NonNull ILogger logger = NoOpLogger.getInstance();
private SentryLevel diagnosticLevel = DEFAULT_DIAGNOSTIC_LEVEL;
private ISerializer serializer;
Expand Down Expand Up @@ -69,6 +70,14 @@ public void setSerializer(ISerializer serializer) {
this.serializer = serializer;
}

public boolean isEnableNdk() {
return enableNdk;
}

public void setEnableNdk(boolean enableNdk) {
this.enableNdk = enableNdk;
}

public long getShutdownTimeout() {
return shutdownTimeoutMills;
}
Expand Down
1 change: 0 additions & 1 deletion sentry-sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@
<meta-data android:name="io.sentry.debug" android:value="true" />
<!-- <meta-data android:name="io.sentry.auto-init" android:value="false" /> // how to disable the auto-init-->
</application>

</manifest>
2 changes: 1 addition & 1 deletion settings.gradle.kts
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")