0

我在我的应用程序中使用 Fabric.io 的 crashytics。

这是我MainActivity.java在最后一个方法中初始化它的onCreate()方式:

Fabric.with(this, new Crashlytics());

这是build.gradle (Project: abc)文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public'}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.google.gms:google-services:3.0.0'
        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 {
        jcenter()
        maven { url "https://dl.bintray.com/hani-momanii/maven"}
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是build.gradle (Module: app)文件:

apply plugin: 'com.android.application'

apply plugin: 'io.fabric'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"

    defaultConfig {
        applicationId "com.xxx.abc"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    repositories {
        mavenCentral()
        maven {
            url "https://jitpack.io"
        }
        maven { url 'https://maven.fabric.io/public' }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
        transitive = true;
    }
}

apply plugin: 'com.google.gms.google-services'

<meta-data android:name="io.fabric.ApiKey" android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />在标签AndroidManifest.xml之间定义。<application>

问题是,当应用程序在未连接到 Android Studio 时崩溃时,我无法获取崩溃报告,尽管当应用程序在连接到它时崩溃时我会收到报告。

为什么会发生这种情况?无论是否连接到 Android Studio,每次应用程序崩溃时,我如何获取崩溃报告?

4

1 回答 1

2

从Application类中删除Activity并放入其中

public class MyApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();
    Fabric.with(this, new Crashlytics());

}

不要忘记在应用程序标签中添加名称manifest.xml

<application
    ...
    android:name=".MyApplication"
    ...
</application>
于 2017-02-21T18:36:56.470 回答