騰訊Bugly應用升級使用總結
前言
最近正在新上線專案,照以往慣例複製來了以前一直在用的一套檢查更新的程式碼,手寫的升級邏輯還是很煩的,要調介面,每次複製過來還要針對新專案修修補補,今天無意間看到騰訊的bugly也有這麼一個功能而且看介紹比較方便,就嘗試著用了一下,跟著文件走還是比較容易整合的,不過還是把一些注意點補充一下以便日後更加方便。
整合步驟
一、配置相關
0.官方文件連結:ofollow,noindex">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);