正常情况下,先编译bsdiff和bspatch,然后使用bsdiff编译出新旧apk的增量包
如果系统环境正常,可以参考http://kinggoo.com/bsdiffupdate.htm
Android增量升级这东西很不错,当时我们这运营的人把百度的一个管理软件拿过来说他们这个升级包提示可以节省流量是怎么回事,当时各种猜测,难道是有什么特殊算法将包压缩了?特意试了一下压缩,根本大小就没变化~后来开发的人找到是增量升级,文章抛给我研究下。拿过来后发现如果单纯的用命令处理真的很简单,当时想法也是很简单,就是让开发把bspatch这个命令内嵌到Apk包里,反正它不大,但后来我在Android模拟器里试了一下,发现根本不行,在继续看参考的那篇文章,发现下面还有,c++这部分要弄成so包,然后在通过javah 去生成一个中间的class才能执行bspatch(另一个开发研究的,在参考的那篇文章里也有这个处理方法)
bsdiff网站:http://www.daemonology.net/bsdiff/
windows:
http://sites.inka.de/tesla/download/bsdiff4.3-win32.zip (32bit)
http://sites.inka.de/tesla/download/bsdiff4.3-win32-src.zip (32bit)
linux:
http://www.daemonology.net/bsdiff/bsdiff-4.3.tar.gz
执行
tar -zxvf bsdiff-4.3.tar.gz cd bsdiff-4.3
编辑Makefile,因为编译器的问题多数编译会出问题(Makefile:13: *** 遗漏分隔符 。 停止。)
原因是:目标体下一行的,命令要用TAB键开头,且不能隔一行。
也就是说在.ifndef的前面要有TAB开头才可以~因为他是安装的下一个子集命令。
修改文件为:
[root@ubuntubsdiff-4.3]# cat Makefile CFLAGS += -O3 -lbz2 PREFIX ?= /usr/local INSTALL_PROGRAM ?= ${INSTALL} -c -s -m 555 INSTALL_MAN ?= ${INSTALL} -c -m 444 all: bsdiff bspatch bsdiff: bsdiff.c bspatch: bspatch.c install: ${INSTALL_PROGRAM} bsdiff bspatch ${PREFIX}/bin .ifndef WITHOUT_MAN ${INSTALL_MAN} bsdiff.1 bspatch.1 ${PREFIX}/man/man1 .endif
开始编译安装bsdiff和bspatch
[root@ubuntubsdiff-4.3]# make [root@ubuntubsdiff-4.3]# ls bsdiff bsdiff.1 bsdiff.c bspatch bspatch.1 bspatch.c Makefile
好了,我们要得到的两个文件bsdiff、bspatch都有了
由于测试一下,所以我就直接传到这台机器上两个apk文件,名为v1.1.apk、v1.0.apk
先来看下当前文件夹内文件信息(因为是测试,所以是直接在bsdiff源码目录下直接操作的)
注意一下,那两个apk文件的大小
[root@ubuntubsdiff-4.3]# ls -l 总计 11260 -rwxr-xr-x 1 root root 14102 05-28 14:25 bsdiff -rw-r--r-- 1 1001 1002 2226 2005-08-17 bsdiff.1 -rw-r--r-- 1 1001 1002 10107 2005-08-17 bsdiff.c -rwxr-xr-x 1 root root 11463 05-28 14:25 bspatch -rw-r--r-- 1 1001 1002 2038 2005-08-17 bspatch.1 -rw-r--r-- 1 1001 1002 5996 2005-08-17 bspatch.c -rw-r--r-- 1 1001 1002 324 05-28 14:25 Makefile -rwxr-xr-x 1 root root 3805331 05-28 14:53 v1.0.apk -rwxr-xr-x 1 root root 3740504 05-28 14:53 v1.1.apk
v1.0.apk大小3805331(3.8M)
v1.1.apk大小3740504(3.7M)
由于1.1有版本优化,所以反而小了。不用管他,执行如下操作:
bsdiff 旧apk 新apk 增量文件
root@ubuntu:/var/www/bsdiff$ ./bsdiff
bsdiff: usage: ./bsdiff oldfile newfile patchfile
[root@ubuntubsdiff-4.3]# ./bsdiff v1.0.apk v1.1.apk diff.patch
格式: bsdiff 上一版本apk包 本版本 对比增量差异部分
通过ls -l查看发现多出 diff.patch文件,大小为1842353(1.8M),用户也就只需要下载这1.8M大小的增量包即可
在使用bspatch,将其增量部分与上一版本包合成
[root@ubuntubsdiff-4.3]# ./bspatch v1.0.apk v1.1_diff_patch.apk ./diff.patch
对合成升级版本的apk包及最新版本apk包进行MD5、SHA1效验
md5效验
[root@ubuntubsdiff-4.3]# md5sum v1.1_diff_patch.apk #合成包 a7d9af832a5e546e3fdce2d1b29c930e v1.1_diff_patch.apk [root@ubuntubsdiff-4.3]# md5sum v1.1.apk #原始升级包 a7d9af832a5e546e3fdce2d1b29c930e v1.1.apk
sha1效验
[root@ubuntubsdiff-4.3]# sha1sum v1.1_diff_patch.apk 94fe99bc40bab8908bccce70aa6a68c5a4fd11b1 v1.1_diff_patch.apk [root@ubuntubsdiff-4.3]# sha1sum v1.1.apk 94fe99bc40bab8908bccce70aa6a68c5a4fd11b1 v1.1.apk
以上均无问题
最后将合成包安装到2.3.3系统上是没有任何问题!
下步是生成给android应用内调用的.so包,下篇文章会介绍,暂时没时间。
----------------------------------------正常操作完成------------------------------------------------------
------------------------------------ubuntu下,编译出问题看下面------------------------------------------------
缺少bzip2
root@ubuntu:/var/www/bsdiff$ make
cc -O3 -lbz2 bsdiff.c -o bsdiff
bsdiff.c:33:19: fatal error: bzlib.h: No such file or directory
compilation terminated.
make: *** [bsdiff] Error 1
需要安装bzip2
root@ubuntu:/var/www/bsdiff$ apt-get install bzip2
安装完成之后,很可能还是会报错
root@ubuntu:/var/www/bsdiff$ sudo make
cc -O3 -lbz2 bsdiff.c -o bsdiff
/tmp/ccJDZUkY.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 returned 1 exit status
make: *** [bsdiff] Error 1
这下蒙逼了,网上也没找到什么好办法,只能直接下载别人编译好的文件了
linux 64位系统下载: http://www.cjblog.org/bsdiff-bspatch.zip
还有一个最简单便捷的方法,直接用apt-get install 安装
root@ubuntu:/var/test$ sudo apt-get install bsdiff
Reading package lists... Done
Building dependency tree
Reading state information... Done
下列【新】软件包将被安装:
bsdiff
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 827 个软件包未被升级。
需要下载 13.4 kB 的软件包。
解压缩后会消耗掉 86.0 kB 的额外空间。
获取:1 http://mirrors.163.com/ubuntu/ precise/universe bsdiff amd64 4.3-10ubuntu1 [13.4 kB]
下载 13.4 kB,耗时 0s (27.3 kB/s)
选中了曾被取消选择的软件包 bsdiff。
(正在读取数据库 ... 系统当前共安装有 136304 个文件和目录。)
正在解压缩 bsdiff (从 .../bsdiff_4.3-10ubuntu1_amd64.deb) ...
正在处理用于 man-db 的触发器...
正在设置 bsdiff (4.3-10ubuntu1) ...
不带参数测试一下分离和合并
root@ubuntu:/var/test$ bsdiff
bsdiff: usage: bsdiff oldfile newfile patchfile
[root@ubuntu/]# bspatch
bspatch: usage: bspatch oldfile newfile patchfile
大功搞成,何必这么麻烦编译源代码~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------Centos 看下面-------------------------------------------------
centos下,直接安装bsdiff就好了
[root@iZ34hknag0hZ bsdiff]# yum install bsdiff
Loaded plugins: fastestmirror, priorities
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* epel: mirrors.aliyuncs.com
http://download.opensuse.org/repositories/home%3A/oojah%3A/mqtt/CentOS_CentOS-5/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bsdiff.x86_64 0:4.3-7.el6 will be installed
--> Finished Dependency ResolutionDependencies Resolved
=========================================================================================================================================================================================================
Package Arch Version Repository Size
=========================================================================================================================================================================================================
Installing:
bsdiff x86_64 4.3-7.el6 epel 13 kTransaction Summary
=========================================================================================================================================================================================================
Install 1 Package(s)Total download size: 13 k
Installed size: 21 k
Is this ok [y/N]: y
Downloading Packages:
bsdiff-4.3-7.el6.x86_64.rpm | 13 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : bsdiff-4.3-7.el6.x86_64 1/1
Verifying : bsdiff-4.3-7.el6.x86_64 1/1Installed:
bsdiff.x86_64 0:4.3-7.el6Complete!
不带参数测试一下分离和合并
[root@iZ34hknag0hZ wwwroot]# bsdiff
bsdiff: usage: bsdiff oldfile newfile patchfile
[root@iZ34hknag0hZ /]# bspatch
bspatch: usage: bspatch oldfile newfile patchfile
证明可以运行了,大功告成!!!!!!!!