在android开发中,越到后面生成apk文件越来越大,每次用户更新都是全部下载更新,浪费时间和流量,如果能增量更新就不错了,使用bsdiff就是为了生成更新包

bsdiff下载地址:http://www.daemonology.net/bsdiff/

下载后解压文件,到文件目录中,执行make

你会发现不能通过,报错了

Makefile:13: *** missing separator.  Stop.

这是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

13行开始到最后前面加TAB,为什么要这样请自行查阅makefile的规则了

保存后再make

还是有问题,不过bsdiff正常生成了

bspatch.c:39:21: error: unknown type name 'u_char'; did you mean 'char'?
static off_t offtin(u_char *buf)
^~~~~~
char
bspatch.c:65:8: error: expected ';' after expression
u_char header[32],buf[8];
^
;
bspatch.c:65:2: error: use of undeclared identifier 'u_char'; did you mean
'putchar'?
u_char header[32],buf[8];
^~~~~~
putchar
/usr/include/stdio.h:261:6: note: 'putchar' declared here
int putchar(int);
^
bspatch.c:65:9: error: use of undeclared identifier 'header'
u_char header[32],buf[8];
^
bspatch.c:65:20: error: use of undeclared identifier 'buf'
u_char header[32],buf[8];
^
bspatch.c:66:2: error: use of undeclared identifier 'u_char'; did you mean
'putchar'?
u_char *old, *new;
^~~~~~
putchar
/usr/include/stdio.h:261:6: note: 'putchar' declared here
int putchar(int);
^
bspatch.c:66:10: error: use of undeclared identifier 'old'
u_char *old, *new;
^
bspatch.c:66:16: error: use of undeclared identifier 'new'
u_char *old, *new;
^
bspatch.c:93:12: error: use of undeclared identifier 'header'
if (fread(header, 1, 32, f) < 32) {
^
bspatch.c:100:13: error: use of undeclared identifier 'header'
if (memcmp(header, "BSDIFF40", 8) != 0)
^
bspatch.c:104:19: error: use of undeclared identifier 'header'
bzctrllen=offtin(header+8);
^
bspatch.c:105:19: error: use of undeclared identifier 'header'
bzdatalen=offtin(header+16);
^
bspatch.c:106:17: error: use of undeclared identifier 'header'
newsize=offtin(header+24);
^
bspatch.c:137:5: error: use of undeclared identifier 'old'
((old=malloc(oldsize+1))==NULL) ||
^
bspatch.c:139:12: error: use of undeclared identifier 'old'
(read(fd,old,oldsize)!=oldsize) ||
^
bspatch.c:141:6: error: use of undeclared identifier 'new'
if((new=malloc(newsize+1))==NULL) err(1,NULL);
^
bspatch.c:147:43: error: use of undeclared identifier 'buf'
lenread = BZ2_bzRead(&cbz2err, cpfbz2, buf, 8);
^
bspatch.c:151:19: error: use of undeclared identifier 'buf'
ctrl[i]=offtin(buf);
^
bspatch.c:159:42: error: use of undeclared identifier 'new'
lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]);
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [bspatch] Error 1

错误很明显,找不到u_char等,因为缺少了头文件

在文件中加入

#include <sys/types.h>
一般这个文件会放到/usr/include/sys/types.h,可以自行查看源码,很简单

再次make就好了

bsdiff使用很简单

bsdiff oldfile newfile patchfile

oldfile:旧的文件

newfile:生成的新文件

patchfile:生成的patch文件

  

05-11 18:11