https://spruce-sentry.stage.yunshanmeicai.com/sentry/java/getting-started/java-android/官方文档
https://spruce-sentry.stage.yunshanmeicai.com/sentry/steward-app/getting-started/java/ 官方文档2
1.gradle添加 compile 'io.sentry:sentry-android:1.7.5'
2.添加SentryUtil类
public class SentryUtil {
private static SentryClientsentryClient;
public static void init() {
sentryClient = SentryClientFactory.sentryClient(BuildConfig.SENTRY_DSN,new AndroidSentryClientFactory(MyApplication.contextApp));
}
public static void sendSentryExcepiton(Throwable throwable) {
if (sentryClient !=null) {
sentryClient.sendException(throwable);
}
}
public static void sendSentryExcepiton(Event throwable) {
if (sentryClient !=null) {
sentryClient.sendEvent(throwable);
}
}
public static void sendSentryExcepiton(EventBuilder throwable) {
if (sentryClient !=null) {
sentryClient.sendEvent(throwable);
}
}
public static void sendSentryExcepiton(String logger, Throwable throwable) {
SentryUtil.sendSentryExcepiton(new EventBuilder()
.withMessage("try catch msg")
.withLevel(Event.Level.WARNING)
.withLogger(logger)
.withSentryInterface(new ExceptionInterface(throwable)));
}
}
其中BuildConfig.SENTRY_DSN为sentry的项目的Settings里的Client Keys选项表里的DSN (Deprecated)值。示例:http://0818b0f59fb947f18bdf6e6fb0931ea5:25dc6334e08545a1b2dc0710fd9af1b2@spruce-sentry.stage.yunshanmeicai.com/33
3.程序Application类onCreate时调用SentryUtil.init();
4.在需要上报crash的地方添加sendSentryExcepiton的调用
网友评论