腾讯的崩溃收集__________Bugly的集成

官方服务

bugly.qq.com

appid和appkey的申请

不是我做的...

导包,

远程仓库支持jcenter,maven
buildscript {
    ....
    repositories {
        jcenter()
    }
}
module中:
android {
    ...
    defaultConfig {
        ...
        //bugly的ndk支持库,建议开启x86作为测试用
        ndk {
            abiFilters 'armeabi' , 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
        }
    }
}
    //bugly 
    compile 'com.tencent.bugly:crashreport:2.2.0'
    //buglyndk
    compile 'com.tencent.bugly:nativecrashreport:2.2.0'

配置权限

    
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.READ_LOGS" />

初始化

2.2.0以后支持在配置文件中设置
    <application>
        <meta-data
            android:name="BUGLY_APPID"
            android:value="appId" />
        
        <meta-data
            android:name="BUGLY_APP_VERSION"
            android:value="1.6.0" />
        
        <meta-data
            android:name="BUGLY_APP_CHANNEL"
            android:value="xiaomi" />
        
        <meta-data
            android:name="BUGLY_ENABLE_DEBUG"
            android:value="true" />
    application>
public class MyApp  extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        //初始化bugly
        //回调,可以不设置
        CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(this);
        strategy.setCrashHandleCallback(new CrashReport.CrashHandleCallback() {
            public Map onCrashHandleStart(int crashType, String errorType,
                                                          String errorMessage, String errorStack) {
                LinkedHashMap map = new LinkedHashMap();
                map.put("测试key", "测试value");
                return map;
            }

            @Override
            public byte[] onCrashHandleStart2GetExtraDatas(int crashType, String errorType,
                                                           String errorMessage, String errorStack) {
                try {

                    return "Extra data.".getBytes("UTF-8");
                } catch (Exception e) {
                    return null;
                }
            }

        });
        //完成初始化,不设置回调CrashReport.initCrashReport(this);
        CrashReport.initCrashReport(getApplicationContext(),strategy);
        //用于测试
        CrashReport.testJavaCrash();
    }

你可能感兴趣的:(实用工具)