Android Studio 接入Fabric- Crashlytics监测系统异常

Fabric-Crashlytics

Fabric是国外流行的log收集与分析工具,可以随时查看系统异常情况并进行分析统计。

  • what
  • why
  • how

what

Fabric简介

Fabric是国外流行的log收集与分析工具,实时了解你的程序运行情况,用图表的方式实时展示出来,达到实时监控的效果。

why

  • 做出更明智,更快的决策,
    关键的应用程序数据如用户活动,稳定的问题,直接展示一个直观的界面,为你提供关于应用程序的明确的答案。

  • 多方协作,一起工作。

  • 可以在任何特定的时刻监视所有的关键应用程序如DAU,事故率等。

how

step 1

官网:https://get.fabric.io/ 注册一个账户

Android Studio 接入Fabric- Crashlytics监测系统异常_第1张图片

step 2

1.安装Fabric插件
Android Studio 接入Fabric- Crashlytics监测系统异常_第2张图片

2.安装成功后, 重启Android Studio, 工具栏会出现一个Fabric的小图标,输入刚刚注册的帐号进行登录。
Android Studio 接入Fabric- Crashlytics监测系统异常_第3张图片

3.点击New App 按钮, 然后选择你要集成Fabric的项目, 然后点击next按钮,一直下一步安装就可以
这里写图片描述

Android Studio 接入Fabric- Crashlytics监测系统异常_第4张图片

Android Studio 接入Fabric- Crashlytics监测系统异常_第5张图片

4.生成配置代码;配置有两种类型: Java 和 Java+NDK. 选择Java, 点击Apply按钮, 配置代码就会自动插入到项目相应的文件中。
这里写图片描述

5.这时你的项目就配置好了Fabric,具体配置代码系统会进行自动配置。无需手动添加。

AndroidManifest.xml 主要是一个key的配置


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.fabricdemo">

    <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=".MainActivity">
            <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="f8fb47e1b3163b76a252eb959e1725a4cb1a3c72" />
    application>

    <uses-permission android:name="android.permission.INTERNET" />
manifest>

build.gradle 主要是仓库和插件的配置

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.dhc.fabricdemo"
        minSdkVersion 27
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:0.5'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
    compile('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
        transitive = true;
    }
}

XxxApplication.java Application中初始化

public class FabricApplication extends Application {
    @Override
    public void onCreate() {
        Fabric.with(this, new Crashlytics());
        super.onCreate();
    }
}

这些就是Fabric的具体配置,这时就可以在Fabric中实时监控的的应用程序。
Android Studio 接入Fabric- Crashlytics监测系统异常_第6张图片

总结

具体的配置很简单,毕竟只是一个工具,而工具讲究的就是简洁,方便,快速,具体的使用就看你是在写代码还是写Bug。

你可能感兴趣的:(andriod-学习)