整合騰訊bugly的熱修復功能sdk步驟
阿新 • • 發佈:2019-01-04
首先為什麼要整合bugly熱修復。市面上有其他的熱修復框架,為什麼就用bugly?這裡給出2張圖大家就明白了。
引用騰訊bugly官網的一段話:
- 無需關注Tinker是如何合成補丁的
- 無需自己搭建補丁管理後臺
- 無需考慮後臺下發補丁策略的任何事情
- 無需考慮補丁下載合成的時機,處理後臺下發的策略
- 我們提供了更加方便整合Tinker的方式
- 我們提供應用升級一站式解決方案
- 打基準包安裝並上報聯網(注:填寫唯一的tinkerId)
- 對基準包的bug修復(可以是Java程式碼變更,資源的變更)
- 修改基準包路徑、填寫補丁包tinkerId、mapping檔案路徑、resId檔案路徑
- 執行tinkerPatchRelease打Release版本補丁包
- 選擇app/build/outputs/patch目錄下的補丁包並上傳(注:不要選擇tinkerPatch目錄下的補丁包,不然上傳會有問題)
- 編輯下發補丁規則,點選立即下發
- 重啟基準包,請求補丁策略(SDK會自動下載補丁併合成)
- 再次重啟基準包,檢驗補丁應用結果
1:新建基準包工程專案(人為製造有BUG的app版本)
- btn.setOnClickListener(new View.OnClickListener() {
- @Override
-
publicvoid
- / String str = LoadBugClass.getBugString();
- String str = BugClass.bug();
- Toast.makeText(MainActivity.this,str,Toast.LENGTH_SHORT).show();;
- }
- });
- publicclass BugClass {
-
publicstatic String bug(){
- String str = null;
- int str_length = str.length();
- return"this is bug class";
- }
- }
2:接著就是配置相關屬性和新增一個外掛依賴了。
下面也給出我自己配置的過程。
首先在最外層的build.gradle檔案中新增依賴,看下圖:
其次新建sampleapplication和sampleapplicationLike兩個Java類
- package com.henry.testappbugly;
- import android.annotation.TargetApi;
- import android.app.Application;
- import android.content.Context;
- import android.content.Intent;
- import android.content.res.AssetManager;
- import android.content.res.Resources;
- import android.os.Build;
- import android.support.multidex.MultiDex;
- import com.tencent.bugly.Bugly;
- import com.tencent.bugly.beta.Beta;
- import com.tencent.tinker.loader.app.DefaultApplicationLike;
- /**
- * Created by W61 on 2016/11/29.
- */
- publicclass SampleApplicationLike extends DefaultApplicationLike {
- publicstaticfinal String TAG = "Tinker.SampleApplicationLike";
- public SampleApplicationLike(Application application, int tinkerFlags,
- boolean tinkerLoadVerifyFlag, long applicationStartElapsedTime,
- long applicationStartMillisTime, Intent tinkerResultIntent, Resources[] resources,
- ClassLoader[] classLoader, AssetManager[] assetManager) {
- super(application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime,
- applicationStartMillisTime, tinkerResultIntent, resources, classLoader,
- assetManager);
- }
- @Override
- publicvoid onCreate() {
- super.onCreate();
- // 這裡實現SDK初始化,appId替換成你的在Bugly平臺申請的appId
- Bugly.init(getApplication(), "", true);
- }
- @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
- @Override
- publicvoid onBaseContextAttached(Context base) {
- super.onBaseContextAttached(base);
- // you must install multiDex whatever tinker is installed!
- MultiDex.install(base);
- // 安裝tinker
- // TinkerManager.installTinker(this); 替換成下面Bugly提供的方法
- Beta.installTinker(this);
- }
- @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
- publicvoid registerActivityLifecycleCallback(Application.ActivityLifecycleCallbacks callbacks) {
- getApplication().registerActivityLifecycleCallbacks(callbacks);
- }
- }
- package com.henry.testappbugly;
- import com.tencent.tinker.loader.app.TinkerApplication;
- import com.tencent.tinker.loader.shareutil.ShareConstants;
- /**
- * Created by W61 on 2016/11/29.
- */
- publicclass SampleApplication extends TinkerApplication {
- public SampleApplication() {
- super(ShareConstants.TINKER_ENABLE_ALL, "SampleApplicationLike所在的包名路徑",
- "com.tencent.tinker.loader.TinkerLoader", false);
- }
- }
在在Androidmanifest.xml檔案中配置許可權及application類名
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.henry.testappbugly">
- <application
- android:name=".SampleApplication"
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- 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>
- <!--API 24以上配置-->
- <provider
- android:name="android.support.v4.content.FileProvider"
- android:authorities="com.tencent.bugly.hotfix.fileProvider"
- android:exported="false"
- android:grantUriPermissions="true">
- <meta-data
- android:name="android.support.FILE_PROVIDER_PATHS"
- android:resource="@xml/provider_paths"/>
- </provider>
- &l