如何在模拟器/设备中为应用程序打补丁,类似于Google Play通过“智能应用程序更新”进行的操作? [英] How to patch an application in emulator/device similar to how Google Play is doing with "Smart app updates"?

查看:184
本文介绍了如何在模拟器/设备中为应用程序打补丁,类似于Google Play通过“智能应用程序更新”进行的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在本地(使用 adb 或其他方式)实现Google Play在智能应用更新中的功能?

Is it possible to achieve locally (using adb or other ways) what Google Play is doing in "Smart app updates" ?

我想做的是在PC上创建一个二进制diff(使用某些命令行工具),然后使用Android工具(adb,shell等)将该差异部署到模拟器/设备。

What I want to do is to create a binary diff on the PC (using some command line tools) and then deploy the diff to simulator/device using Android tools (adb, shell, etc).

我知道
https://android.stackexchange.com/questions/36421/what-is-the-applypatch-tool-and-how-does-one-use-it
,它不提供有关如何实际创建和应用补丁的任何信息,只是 adb shell applypatch 是什么。

我试图在此处快速进行修补的C ++ Android实现代码: https://android.googlesource.com/platform/bootable /recovery/+/master/applypatch/main.cpp#167

I tried to take a quick look at the C++ Android implementation code here which does the patching: https://android.googlesource.com/platform/bootable/recovery/+/master/applypatch/main.cpp#167

到目前为止,我使用bsdiff创建了一个二进制diff,显然它使用与Google Play和Android正在使用。但是我不知道该如何实际应用补丁。

So far I created a binary diff using bsdiff, which apparently uses same algorithm with what Google Play and Android is using. But I don't know how to actually apply the patch.

编辑:为澄清起见,这是一个很好的例子:

EDIT: To clarify, here's a good example:


  • 我的PC上有 com.appv1.apk ,并且还安装在设备/仿真器上。 / li>
  • 我的PC上有 com.appv2.apk

  • 使用 bsdiff 我在 com.appv1.apk com.appv2.apk 叫做 diff.bin

  • I have com.appv1.apk on my PC and also installed on the device/emulator.
  • I have com.appv2.apk on my PC.
  • Using bsdiff I create the binary diff between com.appv1.apk and com.appv2.apk called let's say diff.bin

现在,什么是实际的 adb 命令,我需要运行将 diff.bin 部署在设备/仿真器上,以便在部署diff后,设备/仿真器上的 com.appv1.apk 变为 com.appv2.apk

Now, what is the actual adb command I need to run to deploy diff.binon the device/emulator such that after deploying the diff, com.appv1.apk on the device/emulator becomes com.appv2.apk ?

推荐答案

我会说在用法之间打印:

usage: applypatch [-b <bonus-file>] <src-file> <tgt-file> <tgt-sha1> <tgt-size> [<src-sha1>:<patch> ...]
   or  applypatch -c <file> [<sha1> ...]
   or  applypatch -s <bytes>
   or  applypatch -l

Filenames may be of the form
  MTD:<partition>:<len_1>:<sha1_1>:<len_2>:<sha1_2>:...
to specify reading from or writing to an MTD partition.

以及以下注释:

// This program applies binary patches to files in a way that is safe
// (the original file is not touched until we have the desired
// replacement for it) and idempotent (it's okay to run this program
// multiple times).
//
// - if the sha1 hash of <tgt-file> is <tgt-sha1>, does nothing and exits
//   successfully.
//
// - otherwise, if no <src-sha1>:<patch> is provided, flashes <tgt-file> with
//   <src-file>. <tgt-file> must be a partition name, while <src-file> must
//   be a regular image file. <src-file> will not be deleted on success.
//
// - otherwise, if the sha1 hash of <src-file> is <src-sha1>, applies the
//   bsdiff <patch> to <src-file> to produce a new file (the type of patch
//   is automatically detected from the file header).  If that new
//   file has sha1 hash <tgt-sha1>, moves it to replace <tgt-file>, and
//   exits successfully.  Note that if <src-file> and <tgt-file> are
//   not the same, <src-file> is NOT deleted on success.  <tgt-file>
//   may be the string "-" to mean "the same as src-file".
//
// - otherwise, or if any error is encountered, exits with non-zero
//   status.
//
// <src-file> (or <file> in check mode) may refer to an EMMC partition
// to read the source data.  See the comments for the
// LoadPartitionContents() function for the format of such a filename.

这很简单。

因此,使用 diff.bin <修补 com.appv1.apk 的基本命令/ code>并将结果保存到 com.appv2.apk 将是:

So the basic command to patch com.appv1.apk with diff.bin and save the result to the com.appv2.apk would be:

applypatch com.appv1.apk com.appv2.apk <com.appv2.apk SHA1> <com.appv2.apk size> <com.appv1.apk SHA1>:diff.bin

这篇关于如何在模拟器/设备中为应用程序打补丁,类似于Google Play通过“智能应用程序更新”进行的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆