Skip to content

Commit

Permalink
add -> 12 采用 sentry 平台收集错误
Browse files Browse the repository at this point in the history
  • Loading branch information
ducafecat committed Jun 8, 2020
1 parent 7d6faef commit 4e0f0af
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 7 deletions.
6 changes: 6 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
Expand Down Expand Up @@ -90,4 +95,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'io.sentry:sentry-android:2.1.6'
}
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />

<!-- sentry -->
<meta-data android:name="io.sentry.dsn" android:value="https://[email protected]/5265206" />
</application>

<uses-permission android:name="android.permission.INTERNET" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.flutterducafecatnews;

import java.lang.Thread.UncaughtExceptionHandler;
import io.sentry.core.Sentry;

public class CrashHandler implements UncaughtExceptionHandler {

@Override
public void uncaughtException(Thread t, Throwable e) {
Sentry.captureException(e);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.example.flutterducafecatnews

import androidx.annotation.NonNull;
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant


class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
val crashHandler = CrashHandler()
Thread.setDefaultUncaughtExceptionHandler(crashHandler)
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
4 changes: 2 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
#Fri Jun 05 11:09:52 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Binary file added doc/flutter错误收集.xmind
Binary file not shown.
2 changes: 2 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ target 'Runner' do
# Keep pod path relative so it can be checked into Podfile.lock.
pod 'Flutter', :path => 'Flutter'

pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '5.1.2'

# Plugin Pods

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
Expand Down
15 changes: 14 additions & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ PODS:
- Flutter
- "permission_handler (5.0.0+hotfix.6)":
- Flutter
- Sentry (5.1.2):
- Sentry/Core (= 5.1.2)
- Sentry/Core (5.1.2)
- share (0.0.1):
- Flutter
- shared_preferences (0.0.1):
Expand All @@ -40,6 +43,7 @@ DEPENDENCIES:
- path_provider (from `.symlinks/plugins/path_provider/ios`)
- path_provider_macos (from `.symlinks/plugins/path_provider_macos/ios`)
- permission_handler (from `.symlinks/plugins/permission_handler/ios`)
- Sentry (from `https://github.com/getsentry/sentry-cocoa.git`, tag `5.1.2`)
- share (from `.symlinks/plugins/share/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
- shared_preferences_macos (from `.symlinks/plugins/shared_preferences_macos/ios`)
Expand Down Expand Up @@ -68,6 +72,9 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/path_provider_macos/ios"
permission_handler:
:path: ".symlinks/plugins/permission_handler/ios"
Sentry:
:git: https://github.com/getsentry/sentry-cocoa.git
:tag: 5.1.2
share:
:path: ".symlinks/plugins/share/ios"
shared_preferences:
Expand All @@ -81,6 +88,11 @@ EXTERNAL SOURCES:
webview_flutter:
:path: ".symlinks/plugins/webview_flutter/ios"

CHECKOUT OPTIONS:
Sentry:
:git: https://github.com/getsentry/sentry-cocoa.git
:tag: 5.1.2

SPEC CHECKSUMS:
device_info: d7d233b645a32c40dfdc212de5cf646ca482f175
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
Expand All @@ -91,13 +103,14 @@ SPEC CHECKSUMS:
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
path_provider_macos: f760a3c5b04357c380e2fddb6f9db6f3015897e0
permission_handler: b7a0953389e699927c6217933754cdcd0fa2c5a7
Sentry: 7ee9a34a2c075a5e9306a1501d61c93a4b5c2333
share: 0b2c3e82132f5888bccca3351c504d0003b3b410
shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d
shared_preferences_macos: f3f29b71ccbb56bf40c9dd6396c9acf15e214087
shared_preferences_web: 141cce0c3ed1a1c5bf2a0e44f52d31eeb66e5ea9
sqflite: 4001a31ff81d210346b500c55b17f4d6c7589dd0
webview_flutter: d2b4d6c66968ad042ad94cbb791f5b72b4678a96

PODFILE CHECKSUM: 1b66dae606f75376c5f2135a8290850eeb09ae83
PODFILE CHECKSUM: a12b2c18c1b95e0b8349840175e8e460fe93d59e

COCOAPODS: 1.9.1
16 changes: 16 additions & 0 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import UIKit
import Flutter
import Sentry

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {

override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {

SentrySDK.start(options: [
"dsn": "https://[email protected]/5265498",
"debug": true, // Enabled debug when first installing is always helpful
"enableAutoSessionTracking": true
])

NSSetUncaughtExceptionHandler { exception in
print(exception)
SentrySDK.capture(message: exception.description)
SentrySDK.capture(exception: exception)
}

GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)

}
}
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final SentryClient _sentry = new SentryClient(

// 是否开发环境
bool get isInDebugMode {
return true; // false 开始上传 sentry
return false; // false 开始上传 sentry
}

// 上报异常的函数
Expand Down

0 comments on commit 4e0f0af

Please sign in to comment.