第一步:进入阿里云官网,完成注册登录后,

阿里热修复Sophix的使用教程

阿里热修复Sophix的使用教程

阿里热修复Sophix的使用教程

创建成功后:阿里热修复Sophix的使用教程

阿里热修复Sophix的使用教程

 

 

在阿里云上创建项目结束

 

第二步:接下来是在项目中集成热修复:

首先在项目的app的build.gradle中添加

repositories {
    maven {
        url "http://maven.aliyun.com/nexus/content/repositories/releases"
    }

}

 

compile 'com.aliyun.ams:alicloud-android-hotfix:3.2.4'

阿里热修复Sophix的使用教程

阿里热修复Sophix的使用教程

 

第三步:自定义热修复需要的SophixStudApplication类:

阿里热修复Sophix的使用教程

阿里热修复Sophix的使用教程

 

SophixStubApplication的完整代码如下:

/**
 * Sophix入口类,专门用于初始化Sophix,不应包含任何业务逻辑。
 * 此类必须继承自SophixApplication,onCreate方法不需要实现。
 * 此类不应与项目中的其他类有任何互相调用的逻辑,必须完全做到隔离。
 * AndroidManifest中设置application为此类,而SophixEntry中设为原先Application类。
 * 注意原先Application里不需要再重复初始化Sophix,并且需要避免混淆原先Application类。
 * 如有其它自定义改造,请咨询官方后妥善处理。
 */
public class SophixStubApplication extends SophixApplication {
    private final String TAG = "SophixStubApplication";
    private SharedPreferences sp;
    // 此处SophixEntry应指定真正的Application,并且保证RealApplicationStub类名不被混淆。
    @Keep
    @SophixEntry(SpeechApplication.class)
    static class RealApplicationStub {}
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
//         如果需要使用MultiDex,需要在此处调用。
         MultiDex.install(this);
        initSophix();

    }

    @Override
    public void onCreate() {
        super.onCreate();
        //热修复
        SophixManager.getInstance().queryAndLoadNewPatch();
    }

    private void initSophix() {
        sp = getSharedPreferences("config", Context.MODE_PRIVATE);
        String appVersion = "0.0.0";
        try {
            appVersion = this.getPackageManager()
                    .getPackageInfo(this.getPackageName(), 0)
                    .versionName;
        } catch (Exception e) {
        }
        final SophixManager instance = SophixManager.getInstance();
        instance.setContext(this)
                .setAppVersion(appVersion)
                .setSecretMetaData(getResources().getString(R.string.idSecret), getResources().getString(R.string.appSecret), getResources().getString(R.string.rsaSecret))
                .setEnableDebug(true)
                .setEnableFullLog()
                .setPatchLoadStatusStub(new PatchLoadStatusListener() {
                    @Override
                    public void onLoad(final int mode, final int code, final String info, final int handlePatchVersion) {
                        if (code == PatchStatus.CODE_LOAD_SUCCESS) {
                            //Log.i(TAG, "sophix load patch success!");
                        } else if (code == PatchStatus.CODE_LOAD_RELAUNCH) {
                            // 如果需要在后台重启,建议此处用SharePreference保存状态。
                            //Log.i(TAG, "sophix preload patch success. restart app to make effect.");
                            SharedPreferences.Editor editor = sp.edit();
                            editor.putString("hotFix","b1");
                            editor.apply();
                            editor.commit();
                        }
                    }
                }).initialize();
    }
}

 

 

第四步:创建热修复继承之前的application类,如果已存在,则不需要重新创建,该类名必须要和SophixStubApplication中阿里热修复Sophix的使用教程

要一模一样。

 

如果原本项目中没哟创建application类,则创建(该类,可以不填写内容,只要存在onCreate方法):

阿里热修复Sophix的使用教程

 

完成以上步骤后,则代码集成已完成。

第五步:开始打补丁,

假如有Bug的apk版本号是1.0.0,那修复bug后的apk也要是1.0.0,将有bug的apk和修复bug的apk用不同名称保存,接着打开

 

阿里热修复Sophix的使用教程

该程序 进行生成补丁。

该程序的下载步骤:如下

阿里热修复Sophix的使用教程

 

下载成功解压后,点击运行 显示如下:

阿里热修复Sophix的使用教程

将有bug的apk和修复后的apk加入 

再点击设置:

阿里热修复Sophix的使用教程

选择补丁产生后放在何处

如何是debug包,在不需要填写下面的信息,如何是正式包,则需要填写

 

阿里热修复Sophix的使用教程

生成的补丁如上。

 

第六步:

在控制台中,首先添加apk版本号

阿里热修复Sophix的使用教程

 

阿里热修复Sophix的使用教程

添加成功以后,点击上传补丁

 

阿里热修复Sophix的使用教程

 

阿里热修复Sophix的使用教程

 

阿里热修复Sophix的使用教程

 

阿里热修复Sophix的使用教程

阿里热修复Sophix的使用教程

 

 

如果热修复集成成功,那手机上运行的存在bug的apk会被修复,如果加载成功设备总数不为0,则修复成功

阿里热修复Sophix的使用教程

相关文章:

  • 2022-01-13
  • 2021-05-31
  • 2021-09-19
  • 2021-11-21
  • 2021-08-23
  • 2022-01-10
  • 2021-12-08
  • 2021-06-08
猜你喜欢
  • 2022-12-23
  • 2021-06-27
  • 2022-02-18
  • 2021-08-28
  • 2022-12-23
  • 2021-10-12
相关资源
相似解决方案