当前位置:网站首页>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
边栏推荐
- Use and click of multitypeadapter in recycleview
- Creative SVG ring clock JS effect
- The problem of multiple callback of video ads stimulated by applets (offcolse problem)
- Common redis commands in Linux system
- 从数字化过渡到智能制造
- Android SQLite database
- Go crawler framework -colly actual combat (III) -- panoramic cartoon picture capture and download
- What is test development? Can you find a job at this stage?
- C program design topic 18-19 final exam exercise solutions (Part 2)
- Decoupling pages and components using lifecycle
猜你喜欢

C# Winform 最大化遮挡任务栏和全屏显示问题

In the process of enterprise development, I found that a colleague used the select * from where condition for update

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

After 5 years of software testing in didi and ByteDance, it's too real
Fuxin Kunpeng joins in, and dragon lizard community welcomes a new partner in format document technical service

Technologie des fenêtres coulissantes en octets dans la couche de transmission

Color gradient gradient color collection

ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’

微搭低代码中实现增删改查

VNC viewer remote connection raspberry pie without display
随机推荐
Fuxin Kunpeng joins in, and dragon lizard community welcomes a new partner in format document technical service
Tiktok wallpaper applet source code
Decoupling pages and components using lifecycle
Design and practice of vivo server monitoring architecture
Related operations of ansible and Playbook
2021-11-07
C WinForm maximizes occlusion of the taskbar and full screen display
从数字化过渡到智能制造
Signal integrity (SI) power integrity (PI) learning notes (XXV) differential pair and differential impedance (V)
Eliminate duplicate dependencies
Use and click of multitypeadapter in recycleview
D manual destruction may violate memory security
Transition from digitalization to intelligent manufacturing
UE4 WebBrowser chart cannot display problems
Difficult and miscellaneous problems: A Study on the phenomenon of text fuzziness caused by transform
Garbage collection of C closure
Go crawler framework -colly actual combat (I)
[figure database performance and scenario test sharp tool ldbc SNB] series I: introduction to data generator & Application to ges service
打卡smart精灵#1,品牌不缺吸引力,产品本身实力如何?
Microsoft won the title of "leader" in the magic quadrant of Gartner industrial Internet of things platform again!