Android App追踪/分析第三方sdk配置

Crashlytics for Android

https://fabric.io/kits/android/crashlytics/install

根build.gradle配置

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

  dependencies {
    // These docs use an open ended version so that our plugin
    // can be updated quickly in response to Android tooling updates

    // We recommend changing it to the latest version from our changelog:
    // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
    classpath 'io.fabric.tools:gradle:1.+'
  }
}

module里面的build.gradle

apply plugin: 'com.android.application'
// Put Fabric plugin after Android plugin
apply plugin: 'io.fabric'

repositories {
  maven { url 'https://maven.fabric.io/public' }
}
dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.1.1'
  compile 'com.android.support:design:23.1.1'
  compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
    transitive = true;
  }

AndroidManifest.xml中配置


<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >
      <activity android:name=".MainActivity" android:label="@string/app_name" >
        <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=""
      />
  application>
  <uses-permission android:name="android.permission.INTERNET" />
manifest>

MainActivity中配置

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;

public class MainActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Fabric.with(this, new Crashlytics());
      setContentView(R.layout.activity_main);
    }
}

你可能感兴趣的:(Android开发常用工具类)