preface

The main point of this article is to explain how I used SopHix properly in the project. Of course, this is just the practice of two members of my team. Experience always wants to step out, helpful to the classmate is best.

The following is divided into six parts

  • The introduction
  • Official usage procedure
  • Test development hot update repair operation five steps
  • Procedure For Delivering patches
  • How do I handle the pop-up message of forced update after the patch is loaded successfully
  • How to climb the pit

One, the introduction

Thermal repair technology can be described as a hundred flowers bloom, many products claim that they can achieve a full range of full-function thermal repair. But each of them has its own limitations, either unstable, or too big a patch, or inefficient, or too cumbersome to use, and most of the technology seems to work, but the actual experience is not great. In our opinion, there are a lot of technical details that could be done better.

Finally, on June 11, 2017, The Mobile Shopping technology team and Ali Cloud officially released the first ever non-invasive mobile hot update solution — Sophix.

Wan He works for Mobile Taobao.

The Sophix will shatter the debate over thermal repair technology. We can confidently say that Sophix leads the industry in all three areas of Android hot fixes: code fixes, resource fixes, so fixes, and security and ease of use of solutions.

The article introduces yq.aliyun.com/articles/10… The table below, taken from [author’s blog post], compares Sophix to two other major commercial thermal fixes in terms of the most important dimensions of thermal fixes.





Image.png

The only thing that is not supported is the repair of the four major components. This is because if you want to repair the four major components, you must pre-insert proxy components in AndroidManifest and declare all permissions as far as possible, which will add a lot of bloated code to the original app and be very intrusive to the running process of the app. You can insert a few proxy files. That’s what I do in my projects.

Second, the official use steps

Android access process please be sure to read the official documentation carefully. Documentation is the best teacher to create the application first and then quickly tap into the process

Three, the test development of hot update repair operation five steps

  1. Safe_1.5.30 (hardened package, released for online use) test_1.5.31 (modified version number after Base package, and then a test package, to ensure that the code is consistent, used for installation, patch first delivered to this version, Here’s what I did.)

  2. After safe_1.5.30 is released, change the version number to 1.5.33 in your Android Studio to continue development or fix the BUG. Anyway, it needs to be greater than 1.5.31 (because you need to issue a patch to 1.5.31 in Sophix background first for testing, if your local code is not modified, The build will receive patches from the Sophix server when it runs, and the code coverage will leave you confused.)

  3. After dev_1.5.33 is packaged, you need to upload the base package base_1.5.30 to generate the sophiX-patch.jar Patch package. (The generated Patch is not related to the version number.) The tool will only compare the code structure, so, resources, etc.) and then upload it to the Sophix background

  4. Specify the corresponding version number and deliver the patch to test_1.5.31. The mobile phone installation shall be tested and accepted first, and then the official version 1.5.30 shall be issued after the acceptance is successful

  5. Tips: The version under development in Android Studio needs to be larger than Test1.5.31 so that when you run your Build project, you won’t be affected by the patch instructions for 1.5.31 being delivered to the network

Do not modify the Manifest file. I am not using official debugging tools for this purpose. Instead, you can view the log patch loading status directly in the project. Pay more attention to the meaning of each Code, which is also described in the document here. For details, check the Code of PatchStatus class in SDK, which has specific explanation:

4. Patch delivery procedure

The build patch tool assumes that the current version is 1.5.30, and you need to update the test package to 1.5.31. When you do this, you need to compare the apK file generated by the latest code with the Base baseline version 1.5.30. At this time the generated patch file sophiX-patch. jar is uploaded to sophix backend. Patch version is background automatic control. It’s going to be superimposed. If you continue uploading a patch, the patch of the previous version is automatically disabled.

  1. To add the version number, note the format 1.x. x or 1.xxx



    ~J$E2{$(6OFRBSI]WA7Y0MR.png
  2. Upload the patch file and add a description



    bing

    Official management background instructions

5. How to deal with the pop-up prompt of forced update after patch loading successfully

  • Description of forcibly updating patch status: Sophix will call a method to ask for the latest patch when launching the APP. This is usually called before the Super of onCreate() in the Application. Here is the code from my project

    @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); initHotfix(base); } public void onCreate() { SophixManager.getInstance().queryAndLoadNewPatch(); super.onCreate(); . } / / ali hot fix private void initHotfix Context (Context) {SophixManager. GetInstance () setContext (this) .setAppVersion(VersionUtils.getVersionName(this)) .setAesKey(null) .setEnableDebug(false) .setPatchLoadStatusStub((mode,  code, info, HandlePatchVersion) -> {// Patch loading callback String s = "mode:" + mode + "code:" + code + "\npatchVersion:" + handlePatchVersion + "\ninfo:" + info; hotfixController(context, code, handlePatchVersion, s); }).initialize();}).load_nopatch (); }Copy the code
  • Q: After receiving Code 12, some packages need to prompt users to start strong cooling, while others do not need to prompt, and they can be updated by themselves next time. In this case, how to determine the current package is in which case? Need prompting & Don’t need prompting again? A: The official tip to me is that I need to add A push or something. There is no such symbol in the callback. ((^ __ ^) hee hee… If only Shophix had support in the background)

  • This section describes how to notify the user after the patch is successfully delivered when the status is 1 “Load new patch Success.” Note that if the callback status Code is equal to 12, “Please relaunch app to load new patch” is the prompt for cold startup. Here I did not make a judgment call on 12 to restart.

Here are two necessary restart judgment conditions in my own project for reference only.
HotfixPatchVersion = hotfixMustUpdateVersion = hotFixFixPatchVersion = hotfixMustUpdateVersion = hotFixFixPatchVersion = hotfixMustUpdateVersion = hotFixFixPatchVersion = hotfixMustUpdateVersion HotfixLastMustVersion writes the returned patch version to SP records. * 2. After the first download and data is cleared, if a new patch version is forcibly updated, You are advised to define three fields for comparison public static Final String hotfixPatchVersion = "hotfixPatchVersion"; Public static final String hotfixMustUpdateVersion = "hotfixMustUpdateVersion"; Public static final String hotfixLastMustVersion = "hotfixLastMustVersion"; // Specifies the version number of the last forced restartCopy the code

Note:

  1. In this way, the latest patch is loaded in the actual project, and the latest patch version number in the Sophix needs to be changed to the latest patch number. Generally, an additional field (downloadPatchCode) is added to the version update interface for comparison when requested.

  2. When the user is prompted to close, this method can be called to kill the process at an appropriate time after the PatchLoadStatusListener listens to CODE_LOAD_RELAUNCH. Note that processes cannot be killed directly by process.killProcess (process.mypid ()), as this would disturb the internal state of Sophix. Therefore, if you need to kill a process, it is recommended to use this method, which does some proper processing internally before killing the process. I call this method to close when I close directly in a transparent popover prompt judgment.

    SophixManager.getInstance().killProcessSafely();Copy the code

Six, how to climb the pit

The following are the two problems I have encountered. Don’t jump when you encounter problems. Check the logs first, then check the official documents or QA, 70% or 80% can be solved.

Question 1

Hotfix Android SDK: crashed on 4.x mobile OS

In 4 x IllegalAccessException on system: class ref in the pre – verified abnormality, application crash

The reason for the problem is that since we are repairing the complete DEX, classes in the new dex will conflict with classes in the old dex. Therefore, it is necessary to avoid loading classes in the original APK before the initialization of Sophix. For the 4.x version of the system, if classes in the original APK are loaded before the initialization of Sophix, Will affect the repair process, resulting in a crash

Solution help.aliyun.com/knowledge_d… Sophix initializes at the beginning of the Application, while trying to use system classes and avoid using log, etc., or write initialize to attachBaseContext, but query is still at the beginning of onCreat. Install (Base) in attachBaseContext, initialize and query at the beginning of onCreat. Initialize is written to attachBaseContext after multidex.install (base), but Query is still at the top of onCreat

Question 2

It’s a strange problem. The project boss solved it. All I know is I can’t do it. In 4 X devices, using OkHttp as a Fresco “network loader, if released new package (only change a Toast, for example), the download directly after the restart will collapse at the following error: the Process: com. Newtest. Myapplication, PID: Java. Lang. IllegalAccessError: Class ref in the pre – verified Class resolved to unexpected implementation and other models do not. It’s obviously the same mistake as the first one.

Sophix has a Bug with 4.x models: the above error is reported when an instance in an external reference package needs to call another instance method in the same package. But moving the instance from the package into the App and calling the same method won’t. This means that a method in the 4.x reference package cannot call another method in the reference package. Now it has been solved, but 5.0 and above models do not have this Bug, this is just a very strange problem, if you have not encountered it, please skip it

The above two problems also belong to the same problem, a detailed reading of the author’s article will have some enlightenment.

  • I didn’t write a Demo because Sophix was introduced directly in the project branch. Post an official Demo sometime (this is the biggest joke I’ve ever heard)

The above is only their own way of processing, write bad places also hope to correct, there are problems also hope students give directions, O(∩_∩)O thank you! Learn to share ~