关于阿里热修复的问题

最近工作需要研究阿里热修复的功能;

我测试成功的是用的快速接入:

自定义MyApplication继承Application, 初始化hotfix方法写到attachBaseContext里面,以上官方都有。

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        initHotfix();
    }

    private void initHotfix(){
        String appVersion;
        try {
            appVersion = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
        } catch (PackageManager.NameNotFoundException e) {
            appVersion = "1.0";
        }

        SophixManager.getInstance().setContext(this)
                .setAppVersion(appVersion)
                .setAesKey(null)
                .setEnableDebug(true)
                .setPatchLoadStatusStub(new PatchLoadStatusListener() {
                    @Override
                    public void onLoad(int mode, int code, String info, int handlePatchVersion) {
                        String msg = new StringBuilder("").append("Mode:").append(mode)
                                .append(" Code:").append(code)
                                .append(" Info:").append(info)
                                .append(" HandlePatchVersion:").append(handlePatchVersion).toString();
                        Log.d("test", msg);
                    }
                }).initialize();
    }
}

遇到的坑:没注意少写了setEnableDebug(true),就不行,加上了就成了;

依赖的包:直接远程导入要报错,本地导入的;

implementation files('libs/alicloud-android-utils-1.1.3.jar')
implementation files('libs/utdid4all-1.1.5.3_proguard.jar')
implementation(name:'alicloud-android-hotfix-3.2.5', ext:'aar')

导入aar 需要在app.build的android里面加

android{

repositories {
    flatDir {
        dirs 'libs'
    }
}

}

导入新的补丁方法 ,我是写到界面一个按钮点击调用的,最好别写到application的oncreate里;

SophixManager.getInstance().queryAndLoadNewPatch();

关于热更新补丁工具的问题就是注意:设置里面的签名要 同步你的项目签名别项目多了忘记了,导致签名引起的问题。


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值