最初的增量更新应该是Google Play在Google IO 2012 上提出来的,现在被各大应用市场广泛使用。
最近我们也需要用到这个技术,所以研究一下下~
http://kinggoo.com/bsdiffupdate.htm http://blog.csdn.net/hmg25/article/details/8100896 http://my.oschina.net/liucundong/blog/160436 https://github.com/cundong/SmartAppUpdates http://www.eoeandroid.com/thread-307819-1-1.html
这个网址有客户端和服务端的方法介绍: http://www.csdn.net/tag/android%25E5%25B7%25AE%25E5%25BC%2582%25E5%258C%2596%25E5%258D%2587%25E7%25BA%25A7
http://blog.csdn.net/look_down/article/details/17851791 https://github.com/cczscq/smartupdate
http://www.2cto.com/kf/201401/274436.html http://blog.csdn.net/leilu2008/article/details/10210031 https://github.com/SpecialCyCi/AndroidSmartUpdatesDemo http://blog.leepood.com/android-shi-xian-zeng-liang-geng-xin http://download.csdn.net/download/tibib/5581905
哎~~~ 经过3个小时的惨痛测试后,发现行不通啊,我在linux下编译bsdiff, 根本编译不过,总是报错误,如下:
bsdiff-4.3$ make
cc -O3 -lbz2 bsdiff.c -o bsdiff
/tmp/cc3OAqLk.o: In function `main':
bsdiff.c:(.text.startup+0x2b3): undefined reference to `BZ2_bzWriteOpen'
bsdiff.c:(.text.startup+0x968): undefined reference to `BZ2_bzWrite'
bsdiff.c:(.text.startup+0x9b0): undefined reference to `BZ2_bzWrite'
bsdiff.c:(.text.startup+0xa0c): undefined reference to `BZ2_bzWrite'
bsdiff.c:(.text.startup+0xa6b): undefined reference to `BZ2_bzWriteClose'
bsdiff.c:(.text.startup+0xabe): undefined reference to `BZ2_bzWriteOpen'
bsdiff.c:(.text.startup+0xae9): undefined reference to `BZ2_bzWrite'
bsdiff.c:(.text.startup+0xb0f): undefined reference to `BZ2_bzWriteClose'
bsdiff.c:(.text.startup+0xb61): undefined reference to `BZ2_bzWriteOpen'
bsdiff.c:(.text.startup+0xb8c): undefined reference to `BZ2_bzWrite'
bsdiff.c:(.text.startup+0xbb2): undefined reference to `BZ2_bzWriteClose'
collect2: ld 返回 1
make: *** [bsdiff] 错误 1
总是这个错误,没有找到网上有人说解决的~
其实我只需要2个编译好的文件:bsdiff 和 bspatch,就可以在我本地(Ubuntu_linux64的系统)测试了,在无路可走的时候,我突然想起来,在linux的源码中也有这个bsdiff工具类,于是赶紧打开代码,找到external/bsdiff目录下,里面有android.mk, 于是在这个目录下直接mm即可编译,很快就编译成功了,log信息如下:
/dev/android4.4/external/bsdiff$ mm
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.4
TARGET_PRODUCT=aosp_flo
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=krait
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.2.0-59-generic-x86_64-with-Ubuntu-12.04-precise
HOST_BUILD_TYPE=release
BUILD_ID=KRT16O
OUT_DIR=out
============================================
make:进入目录'/android4.4'
build/core/Makefile:32: 警告:覆盖关于目标“out/target/product/flo/system/media/audio/ui/camera_click.ogg”的命令
build/core/Makefile:32: 警告:忽略关于目标“out/target/product/flo/system/media/audio/ui/camera_click.ogg”的旧命令
build/core/Makefile:32: 警告:覆盖关于目标“out/target/product/flo/system/media/audio/ui/camera_focus.ogg”的命令
build/core/Makefile:32: 警告:忽略关于目标“out/target/product/flo/system/media/audio/ui/camera_focus.ogg”的旧命令
build/core/Makefile:32: 警告:覆盖关于目标“out/target/product/flo/system/media/audio/ui/Effect_Tick.ogg”的命令
build/core/Makefile:32: 警告:忽略关于目标“out/target/product/flo/system/media/audio/ui/Effect_Tick.ogg”的旧命令
build/core/Makefile:32: 警告:覆盖关于目标“out/target/product/flo/system/media/audio/ui/KeypressDelete.ogg”的命令
build/core/Makefile:32: 警告:忽略关于目标“out/target/product/flo/system/media/audio/ui/KeypressDelete.ogg”的旧命令
build/core/Makefile:32: 警告:覆盖关于目标“out/target/product/flo/system/media/audio/ui/KeypressReturn.ogg”的命令
build/core/Makefile:32: 警告:忽略关于目标“out/target/product/flo/system/media/audio/ui/KeypressReturn.ogg”的旧命令
build/core/Makefile:32: 警告:覆盖关于目标“out/target/product/flo/system/media/audio/ui/KeypressSpacebar.ogg”的命令
build/core/Makefile:32: 警告:忽略关于目标“out/target/product/flo/system/media/audio/ui/KeypressSpacebar.ogg”的旧命令
build/core/Makefile:32: 警告:覆盖关于目标“out/target/product/flo/system/media/audio/ui/KeypressStandard.ogg”的命令
build/core/Makefile:32: 警告:忽略关于目标“out/target/product/flo/system/media/audio/ui/KeypressStandard.ogg”的旧命令
build/core/Makefile:32: 警告:覆盖关于目标“out/target/product/flo/system/media/audio/ui/Lock.ogg”的命令
build/core/Makefile:32: 警告:忽略关于目标“out/target/product/flo/system/media/audio/ui/Lock.ogg”的旧命令
build/core/Makefile:32: 警告:覆盖关于目标“out/target/product/flo/system/media/audio/ui/LowBattery.ogg”的命令
build/core/Makefile:32: 警告:忽略关于目标“out/target/product/flo/system/media/audio/ui/LowBattery.ogg”的旧命令
build/core/Makefile:32: 警告:覆盖关于目标“out/target/product/flo/system/media/audio/ui/Unlock.ogg”的命令
build/core/Makefile:32: 警告:忽略关于目标“out/target/product/flo/system/media/audio/ui/Unlock.ogg”的旧命令
build/core/Makefile:32: 警告:覆盖关于目标“out/target/product/flo/system/media/audio/ui/VideoRecord.ogg”的命令
build/core/Makefile:32: 警告:忽略关于目标“out/target/product/flo/system/media/audio/ui/VideoRecord.ogg”的旧命令
No private recovery resources for TARGET_DEVICE flo
Import includes file: out/host/linux-x86/obj/EXECUTABLES/bspatch_intermediates/import_includes
host C: bspatch <= external/bsdiff/bspatch.c
Export includes file: external/bsdiff/Android.mk -- out/host/linux-x86/obj/EXECUTABLES/bspatch_intermediates/export_includes
host Executable: bspatch (out/host/linux-x86/obj/EXECUTABLES/bspatch_intermediates/bspatch)
Install: out/host/linux-x86/bin/bspatch
make:离开目录“/android4.4”
OK,编译成功了,那么去对应的目录发现,在out/host/linux-x86/bin/目录下,已经有编译好的bsdiff,bspatch了,还有很多其它的工具,但是我们暂且不看。
然后我用一个应用的两个版本的APK测试一下了!补一句,如果你在window下测试的话,其实更方便,这个网址,http://blog.csdn.net/hmg25/article/details/8100896,里面有windows的测试工具和命令。
命令如下(中间的总是新版本的APK,最后总是差分patch):
- bsdiff iReader1.6.2.0(v35).apk iReader1.8.0.1(v40).apk ireader.patch
- bspatch iReader1.6.2.0(v35).apk new.apk ireader.patch
比如:
A:代表1.0版本
B:代表2.0版本
C:代表差分包
D:用A,C生成的新版本,其实就是B
1.用bsdiff生成差分patch(C):发现确实包小了很多
2.用bspatch:用老版本apk(A),刚刚生成的patch(C),生成新版本的apk(D),发现新版本的APK(D)和最原始的APK(B)的大小是一样的
3.用md5sum 和sha1sum校验了一下新生成的APK(D),与最原始的版本(B)相比,发现2个值都分别相等
最后补充一下,校验md5sum, sha1sum 有什么用呢?md5sum 和 sha1sum 二者多用于计算某个文件的hash值,其实我也没搞懂,参考一下:
http://blog.sina.com.cn/s/blog_609dd4970101011f.html
http://www.pvsky.com/blog/20121003/457.html
太强大了,牛逼~
其实不只用于APK的更新,其它的比如:zip等的更新都可以用这个,因为是二进制的差分么。
附带2个bsdiff, bspatch工具,如果你没有android源码的话,确实这2个工具很难找,我在ubuntu linxu64位下编译的:见这个网址:
http://download.csdn.net/detail/song_shi_chao/7035557