Skip to content

修改由于 code-push 的 release 命令发布热更新可能导致hash值不同bug #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2019

Conversation

openUmbrella
Copy link
Contributor

存在的问题

通过code-push的 release 命令直接上传包到服务器时, 生成的hash值可能会与生成iOS应用包时,包含进入的RN包的hash值不一致。

产生问题的具体步骤如下:

  1. 我先手动打了一个bundle包,命令如下:
react-native bundle --entry-file index.ios.js --platform ios --dev false --bundle-output "/Users/jeff.li/Desktop/bundle/main.jsbundle" --assets-dest "/Users/jeff.li/Desktop/bundle"

此时,我电脑的桌面上有一个bundle文件夹,里面包含main.jsbundle和asserts文件

  1. 使用上一步骤生成的RN包传到热更新服务器,使用如下命令:
code-push release "myapp" "/Users/jeff.li/Desktop/bundle" "3.7.3" --d "Staging" --des "更新bundle啦" --m "true"
  1. 运行iOS应用,通过抓包发现,检查更新时,即使是同样的代码,hash是不一样的。这就导致了应用必须全量再下载一次RN包。(也就没有达到使用原则第五条所说的:每次向App Store提交新的版本时,也应该基于该提交版本同时向code-push-server发布一个初始版本。(因为后面每次向code-push-server发布版本时,code-puse-server都会和初始版本比较,生成补丁版本))

原因分析

因为在iOS应用中,CodePush这个框架在计算打包进入应用的RN包的hash值时,在解析路径时,固定地使用了这样的相对路径来计算hash值:
CodePush/main.jsbundle:hash值
CodePush/assets/图片路径:图片hash值
image
image

最终要计算hash值的字符串形如:
image

而在code-push-server这边的计算方式与CodePush的计算方式是一样的,不过存在一点差异:
就是在解压包之后,就按着这个包的内容来进行进行hash运算,最终就导致了最终要计算的hash值字符串不一致了,如下图所示:
image

因为相对路径值不同,导致最终计算得到的hash值不同

Pull Request

我的修改方案是 core/utils/security.js文件中做如下修改:
image

确保相对路径的开头是CodePush

@lisong lisong merged commit 3442698 into lisong:master Nov 17, 2019
aaron-xue pushed a commit to aaron-xue/code-push-server that referenced this pull request Nov 20, 2019
修改由于 code-push 的 release 命令发布热更新可能导致hash值不同bug (lisong#236)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants