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的項(xiàng)目的Settings里的Client Keys選項(xiàng)表里的DSN (Deprecated)值铃拇。示例:http://0818b0f59fb947f18bdf6e6fb0931ea5:25dc6334e08545a1b2dc0710fd9af1b2@spruce-sentry.stage.yunshanmeicai.com/33
3.程序Application類onCreate時(shí)調(diào)用SentryUtil.init();
4.在需要上報(bào)crash的地方添加sendSentryExcepiton的調(diào)用