使用Android中的结构发送崩溃报告。已在MainActivity的throw RuntimeException("This is a crash");
上使用OnCreate
。崩溃报告将被上传,否则,如果它在按钮单击侦听器中使用或在创建时具有其他任何主动性,则不会上传崩溃报告。这是
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
}
Gradle版本 4.4 Android插件版本 3.1.4
清单
<meta-data
android:name="firebase_analytics_collection_enabled"
android:value="false" />
<meta-data
android:name="io.fabric.ApiKey"
android:value="5c23f20ffeaecaa62e433c9b6229b1b40fb8a483"
/>
应用级优惠券
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 27
// buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.first"
minSdkVersion 19
targetSdkVersion 27
versionCode 45
versionName "2.1.6"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-fresco.pro'
}
}
configurations {
all {
exclude group: 'org.json', module: 'json'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:design:27.1.1'
implementation 'com.razorpay:checkout:1.4.9'
implementation "com.razorpay:razorpay-java:1.3.8"
implementation 'com.facebook.android:facebook-android-sdk:4.16.1'
implementation 'com.facebook.fresco:fresco:1.9.0'
// implementation 'com.github.freshdesk:hotline-android:1.2.3'
implementation 'com.github.freshdesk:freshchat-android:1.5.2'
// implementation 'com.google.android.gms:play-services:15.0.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'io.branch.sdk.android:library:2.18.1'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
testImplementation 'junit:junit:4.12'
implementation 'com.google.firebase:firebase-messaging:17.3.2'
implementation 'com.google.firebase:firebase-crash:16.2.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
transitive = true;
}
implementation 'com.google.firebase:firebase-core:16.0.3'
}
apply plugin: 'com.google.gms.google-services'
项目级别gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:4.1.0'
// classpath 'io.fabric.tools:gradle:1.26.0'
classpath 'io.fabric.tools:gradle:1.25.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
maven {
url 'https://jitpack.io' }
mavenCentral()
jcenter()
maven {
url 'https://maven.google.com/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
答案 0 :(得分:0)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
setContentView(R.layout.activity_main);
throw new RuntimeException("This is a crash");
}
清单
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".activity.MainActivity"
android:label="@string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="4*************************" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
构建Gradle
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'io.fabric.tools:gradle:1.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradel模块应用
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
........
........
}
dependencies {
........
........
implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
transitive = true;
}
}
编辑2
您可以通过抛出未捕获的异常来查看是否成功添加了崩溃报告,例如:
throw new RuntimeException("This is a crash");
崩溃是在您的应用重新打开后发送的,因此请确保将此行放置在Application类或启动Activity的onCreate()方法之外;添加按钮触发崩溃通常效果很好。
我们实时处理崩溃。如果我们检测到崩溃是由新问题引起的,它将在您的仪表板上显示为新问题。如果是现有问题的重复发生,则该问题的崩溃计数器将增加,并且来自新崩溃的信息将包含在问题中。
如果您没有看到崩溃的情况,请检查以下常见的延迟原因:
Crashlytics.getInstance().crash()
方法用于
测试目的,请确保不在您的onCreate方法中
启动活动