Crashlytics - 当应用程序在未连接到 android studio 时崩溃时无法获取崩溃报告
Crashlytics - Unable to get crash reports when the app crashes while not connected to android studio
我在我的应用程序中使用 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"
/>
定义在 <application>
标签之间的 AndroidManifest.xml
。
问题是每当应用程序在未连接到 Android Studio 时崩溃时我无法获取崩溃报告,尽管我在应用程序时收到报告连接时崩溃。
为什么会发生这种情况,我如何每次应用程序崩溃时都获取崩溃报告,无论是否连接到 Android Studio?
从 Activity
中删除并放入 Application class
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
}
不要忘记在 manifest.xml
的 Application 标签中添加名称
<application
...
android:name=".MyApplication"
...
</application>
我在我的应用程序中使用 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"
/>
定义在 <application>
标签之间的 AndroidManifest.xml
。
问题是每当应用程序在未连接到 Android Studio 时崩溃时我无法获取崩溃报告,尽管我在应用程序时收到报告连接时崩溃。
为什么会发生这种情况,我如何每次应用程序崩溃时都获取崩溃报告,无论是否连接到 Android Studio?
从 Activity
中删除并放入 Application class
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
}
不要忘记在 manifest.xml
<application
...
android:name=".MyApplication"
...
</application>