当前位置:网站首页>Hot fix sophix multi-channel patch solution
Hot fix sophix multi-channel patch solution
2022-06-25 00:26:00 【a10615】
1 background
lately , hold Sophix Integrated into a multi-channel project . but , The first time I used it, I encountered a pit . The code uses BuildConfig.FLAVOR To determine the current channel , Such as :
There are two channels :taobao and tianmao
Test.java class BuildConfig.FLAVOR:
if ("taobao".equals(BuildConfig.FLAVOR)){
toast("abc");
} else {
toast("hello");
}Now we need to ”abc” Switch to ”xyz”.
After replacement , Want to use hot fixes to achieve . About the steps :
- When using old packages mapping, Generate new package ( You can generate packages for only one channel )
- Old and new packages using the same channel , Generate patch file
- Upload patches , Grayscale Publishing
In grayscale Publishing , Find out taobao channel APP Fixed .
and ,tianmao Channel APP, Because they belong to the same version , It will definitely be patched . but , little does one think ,toast The content of , Not the original “hello”, But it became “abc”.
If you use tianmao Channel to generate patches , that tianmao normal . but taobao After the patch is completed , But it became “hello”.
2 Problem solving path
Later, I asked Ali for technical support , Technical support said that the method of using white list . Because I didn't find mapping Obfuscated mapping relationship under file , I just put BuildConfig The original package name and class name of the class are added to the white list : com.ali.six.BuildConfig
result , It is the same as the original effect . Technical support also provides ideas : Is it compiled into constants .
After decompilation, it is found that : Before compiling BuildConfig, After compiling, there is no , The code uses BuildConfig A place worth , Are replaced by constant values .
see BuildConfig After the class , It is found that this kind is final class , All internal variables are member variables , And are all public static final modification . such , After compiling , Where they are used , It must become a constant value .
Patch , It is generated by comparing the differences between old and new packages . therefore , Modified code , It must be within the range of differences , And in this code BuildConfig.FLAVOR, Always a constant value , It is determined by the channel that generates the patch .
such , It explains the problems encountered before .
Last , Use version upgrade to update .
3 Solution
But my heart is not willing to , So like Sophix, It can't be used ? These ideas provided through technical support , Still found a solution : hold BuildConfig Encapsulate into a class MyBuildConfig, Let all the original use to BuildConfig The place of , Use this class instead ; And add this class to the white list . specific working means :
1、 The new class MyBuildConfig( Interface is OK , As the case may be )
2、 Use expressions , Or method , Provide external call interface , Such as :MyBuildConfig.IS_FLAVOR_TAO_BAO. This class , stay taobao After channel compilation , This class will only leave a = “taobao”.equals(“taobao”) This expression .
public class MyBuildConfig {
/** * Direct constants are all encapsulated in classes , Only methods are provided externally 、 Or variables of expressions * No directly usable constants are provided , as a result of : * public static final String FLAVOR = BuildConfig.FLAVOR; * Compile time ,BuildConfig.FLAVOR Is a constant value , All use MyBuildConfig.FLAVOR The place of , Will also become a constant value , such , Or does it affect the code */
private static final String FLAVOR_TAO_BAO = "taobao";
private static final String FLAVOR_TIAN_MAO = "tianmao";
public static final boolean IS_FLAVOR_TAO_BAO = FLAVOR_TAO_BAO.equals(BuildConfig.FLAVOR);
}3、 According to the baseline package mapping, find MyBuildConfig The path of the class after confusion , Add to the white list , Such as :com.ali.six.c
4、 Generate patch file
such , This ensures that the logic of the code will be affected due to different channels . If , The place where the code is fixed has nothing to do with the channel , Then you don't have to use MyBuildConfig
边栏推荐
- D does not require opapply() as a domain
- 从数字化过渡到智能制造
- Use of navigation and navigationui
- 傳輸層 以字節為單比特的滑動窗口技術
- Related operations of ansible and Playbook
- Difficult and miscellaneous problems: A Study on the phenomenon of text fuzziness caused by transform
- Is it so difficult to calculate the REM size of the web page according to the design draft?
- Only positive integers can be entered in the text box
- OTT营销之风正盛,商家到底该怎么投?
- Simple collation of Web cache
猜你喜欢

【排行榜】Carla leaderboard 排行榜 运行与参与手把手教学
[distributed system design profile (2)] kV raft

Xcode预览(Preview)显示List视图内容的一个Bug及解决

Svg+js keyboard control path

Wx applet jump page

I suddenly find that the request dependent package in NPM has been discarded. What should I do?

C# Winform 最大化遮挡任务栏和全屏显示问题
WordPress add photo album function [advanced custom fields Pro custom fields plug-in series tutorial]

Design scheme of authority management of fusion model
Hyperledger Fabric 2. X dynamic update smart contract
随机推荐
C程序设计专题 15-16年期末考试习题解答(上)
Xcode预览(Preview)显示List视图内容的一个Bug及解决
ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’
Wallpaper applet wechat applet
D manual destruction may violate memory security
Network request -volley
Overview of medium and low speed aerospace electronic bus
The problem of multiple callback of video ads stimulated by applets (offcolse problem)
Tiktok wallpaper applet, starlight wallpaper applet version 2.0, upgraded version
Apk decompiled method (not confused)
融合模型权限管理设计方案
JMeter socket connection sends data
More pictures | explain the Nacos parameters in detail!
Eliminate duplicate dependencies
VNC viewer remote connection raspberry pie without display
Some examples of MgO operating database in go
In the process of enterprise development, I found that a colleague used the select * from where condition for update
Go crawler framework -colly actual combat (III) -- panoramic cartoon picture capture and download
A small program written this week
Adding, deleting, modifying and checking in low build code