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 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,24 @@ static void init(SentryOptions options, Context context, ILogger logger) {
ManifestMetadataReader.applyMetadata(context, options);
createsEnvelopeDirPath(options, context);

options.addEventProcessor(new DefaultAndroidEventProcessor(context, options));
options.setSerializer(new AndroidSerializer(options.getLogger()));

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];
Method method = cls.getMethod("init", SentryOptions.class);
Object[] args = new Object[1];
args[0] = options;
args[1] = cacheDirPath;
method.invoke(null, args);
} catch (ClassNotFoundException exc) {
options.getLogger().log(SentryLevel.ERROR, "Failed to load SentryNdk.");
} catch (Exception e) {
options.getLogger().log(SentryLevel.ERROR, "Failed to initialize SentryNdk.", e);
}
}

options.addEventProcessor(new DefaultAndroidEventProcessor(context, options));
options.setSerializer(new AndroidSerializer(options.getLogger()));
}

private static void createsEnvelopeDirPath(SentryOptions options, Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ManifestMetadataReader {
static final String DSN_KEY = "io.sentry.dsn";
static final String DEBUG_KEY = "io.sentry.debug";
static final String AUTO_INIT = "io.sentry.auto-init";
static final String ENABLE_NDK = "io.sentry.ndk";

public static void applyMetadata(Context context, SentryOptions options) {
if (context == null) throw new IllegalArgumentException("The application context is required.");
Expand All @@ -32,6 +33,10 @@ public static void applyMetadata(Context context, SentryOptions options) {
log(options.getLogger(), SentryLevel.DEBUG, "DSN read: %s", dsn);
options.setDsn(dsn);
}

boolean ndk = metadata.getBoolean(ENABLE_NDK, false);
log(options.getLogger(), SentryLevel.DEBUG, "NDK read: %s", ndk);
options.setEnableNdk(ndk);
}
log(
options.getLogger(),
Expand Down
7 changes: 6 additions & 1 deletion sentry-android-ndk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="io.sentry.android.ndk" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.sentry.android.ndk">
<application>
<meta-data android:name="io.sentry.ndk" android:value="true"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static void notifyNewSerializedEnvelope(String path) {
System.out.println("envelope written to " + path);
}

public static void init(SentryOptions options, String cacheDirPath) {
public static void init(SentryOptions options) {
// Java_example
initSentryNative(cacheDirPath);
initSentryNative(options.getCacheDirPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class SentryOptions {
private String dsn;
private long shutdownTimeoutMills;
private boolean debug;
private boolean enableNdk = true;
private boolean enableNdk;
private @NonNull ILogger logger = NoOpLogger.getInstance();
private SentryLevel diagnosticLevel = DEFAULT_DIAGNOSTIC_LEVEL;
private ISerializer serializer;
Expand Down