腾讯Bugly应用升级使用总结

前言

        最近正在新上线项目,照以往惯例复制来了以前一直在用的一套检查更新的代码,手写的升级逻辑还是很烦的,要调接口,每次复制过来还要针对新项目修修补补,今天无意间看到腾讯的bugly也有这么一个功能而且看介绍比较方便,就尝试着用了一下,跟着文档走还是比较容易集成的,不过还是把一些注意点补充一下以便日后更加方便。

集成步骤

一、配置相关

0.官方文档链接:bugly官方文档

1.依赖

注意,如果集成更新sdk那么要注释掉原来的崩溃上报因为这个sdk已经集成了这个功能

android {

        defaultConfig {

          ndk {

            //设置支持的SO库架构            abiFilters ‘armeabi’ //, ‘x86’, ‘armeabi-v7a’, ‘x86_64’, ‘arm64-v8a’          }

        }

      }

      dependencies {

          //注释掉原有bugly的仓库         

          //compile ‘com.tencent.bugly:crashreport:latest.release’

          compile ‘com.tencent.bugly:crashreport_upgrade:latest.release’

          compile ‘com.tencent.bugly:nativecrashreport:latest.release’   

  }

2.权限配置

<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” />

<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” />

<uses-permission android:name=”android.permission.REQUEST_INSTALL_PACKAGES” />

3.Activity配置

<activity

android:name=”com.tencent.bugly.beta.ui.BetaActivity”

android:configChanges=”keyboardHidden|orientation|screenSize|locale”

android:theme=”@android:style/Theme.Translucent” />

4.配置FileProvide

这个是必须配置的 不配置安卓7.0+是用不了的

<provider

android:name=”android.support.v4.content.FileProvider”

android:authorities=”${applicationId}.fileProvider”

android:exported=”false”

android:grantUriPermissions=”true”> 

<meta-data android:name=”android.support.FILE_PROVIDER_PATHS” 

 android:resource=”@xml/provider_paths”/ >

</provider>

注意:如果你拥有其他也需要配置FileProvider的三方库,那么这里需要继承FileProvider来解决冲突问题

配置清单中:

<provider

android:name=”.utils.BuglyFileProvider”   

android:authorities=”${applicationId}.fileProvider”   

android:exported=”false”   

android:grantUriPermissions=”true”   

tools:replace=”name,authorities,exported,grantUriPermissions”>

<meta-data

android:name=”android.support.FILE_PROVIDER_PATHS”

android:resource=”@xml/provider_paths” tools:replace=”name,resource”/ >

</provider>

新建一个继承于V4包FileProvider的空类

packagecom.bimex.wzh.easyconsbox.base;

importandroid.support.v4.content.FileProvider;

/**使用bugly 自定义一个provider

 * Created by Google on 2018/4/25.

 */

public class BuglyFileProvider extends FileProvider {

}

在res目录新建xml文件夹,创建provider_paths.xml文件如下

<paths xmlns:android=”http://schemas.android.com/apk/res/android”>

          <external-path name=”beta_external_path” path=”Download/”/>

          <external-path name=”beta_external_files_path” path=”Android/data/”/>

</paths>

5.混淆配置

-dontwarn com.tencent.bugly.**

-keep public class com.tencent.bugly.**{*;}

-keep class android.support.**{*;}

二、开始使用

1.SDK初始化

注意:如果您之前使用过Bugly SDK,请将以下这句注释掉。

CrashReport.initCrashReport(getApplicationContext(), “注册时申请的APPID”, false);

统一初始化方法:

Bugly.init(getApplicationContext(), “注册时申请的APPID”, false);

    原文作者:此生唯一自传
    原文地址: https://www.jianshu.com/p/43bbc67cc22d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞