Bugly热更新配置

2022-03-18  本文已影响0人  BillyJean

一、热修复技术的应用

热修复技术一般用来在线更新安装包,当热更新包发布后,会提示用户更新,重启应用,修复紧急Bug。下面的只是初级配置,使用的是集成了Tinker的腾讯的Bugly平台。

二、Bugly平台热更新配置步骤

1.第一步:

 dependencies {
        //gradle版本最好设置在4.0以下,高版本可能会出现适配问题
        classpath 'com.android.tools.build:gradle:3.2.0'
        //引入bugly中的tinker支持
        classpath "com.tencent.bugly:tinker-support:1.2.0"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
  // 编译补丁包时,必需指定基线版本的apk,默认值为空
    // 如果为空,则表示不是进行补丁包的编译
    // @{link tinkerPatch.oldApk }
   //如果是debug版本就将所有release替换成debug
    baseApk =  "${bakPath}/${baseApkDir}/app-release.apk"

    // 对应tinker插件applyMapping
    baseApkProguardMapping = "${bakPath}/${baseApkDir}/app-release-mapping.txt"

    // 对应tinker插件applyResourceMapping
    baseApkResourceMapping = "${bakPath}/${baseApkDir}/app-release-R.txt"
public class SampleApplication extends TinkerApplication {
    public SampleApplication() {
        //这里的第二个参数一定要修改为自己的SampleApplicationLike的路径
        super(ShareConstants.TINKER_ENABLE_ALL, "com.bigzing.usehotfix2.SampleApplicationLike",
                "com.tencent.tinker.loader.TinkerLoader", false, true);
    }
}
 // 这里实现SDK初始化,appId替换成你的在Bugly平台申请的appId
        Bugly.init(getApplication(), "xxxxxxxxxx", true);

3.第三步:

apply plugin: 'com.android.application'
// 依赖插件脚本
apply from: 'tinker-support.gradle'
android {
    compileSdkVersion 30
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "com.bigzing.usehotfix2"
        minSdkVersion 15
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        // 开启multidex
        multiDexEnabled true
        ndk {
            // 设置支持的SO库架构
            abiFilters 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'//,'armeabi'
        }
    }

    //签名配置
    signingConfigs {
        config {
            keyAlias "android"
            keyPassword "123456"
            storeFile file('D:\\ASWorkSpace\\UseHotFix2\\app\\src\\android.jks')
            storePassword "123456"
        }
    }
    buildTypes {
        release {
            //签名配置
            signingConfig signingConfigs.config
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

    // 远程仓库集成方式(推荐)
    implementation 'com.tencent.bugly:crashreport_upgrade:1.5.23'
    //1. 指定tinker依赖版本(注:应用升级1.3.5版本起,不再内置tinker)
    //2.为了便于解答问题,这里的tinker版本建议跟随此处demo设置,如果微信更新了tinker版本,bugly会定期同步更新
    implementation 'com.tencent.tinker:tinker-android-lib:1.9.14.10'
    implementation "com.android.support:multidex:1.0.3" // 多dex配置
}

4.第四步:添加用例,并在Activity中调用

public class Utils {
    private static  final String TAG = "Utils";
    public static void test(){
        //Log.i(TAG, "test: ");
        throw new IllegalStateException("出错啦!!!");
    }
}
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    //button的onClick方法实现
    public void UnitTest(View view) {
        Utils.test();
    }
}

5.第五步:

6.第六步:修复并发布补丁包

public class Utils {
    private static  final String TAG = "Utils";
    public static void test(){
        Log.i(TAG, "test: ");
        //throw new IllegalStateException("出错啦!!!");
    }
}
发布补丁包.png
上一篇 下一篇

猜你喜欢

热点阅读