android 增量更新 mac环境

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012629497/article/details/50826724

目前许多程序实现了增量新的技术;本文主要是说明在mac 环境下阐述增量更新的原理和配置过程

1.实现原理

    把例如老v1.0.apk 是2M,v2.0.apk是4M,实现过程就是生成两个包不同的差异包;然后再把差异包放到服务器上面,手机端下载差异包。下载完成之后差异包和老包合并成新包。

 这样就是实现不用下载整个apk  从而实现增量更新

2.准备工具

bsdiff网站http://www.daemonology.net/bsdiff/   

终端来到这个目录

harrishuangdeMacBook-Pro:bsdiff-4.3 3 harrishuang$ ls

Makefile bsdiff.1 bsdiff.c bspatch.1 bspatch.c

开始执行编译安装(这里会出现两个坑)

$ make

1.makefile会出现错误

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

解决方法:在13行和15行前面加tab

2.bspatch.c中的错误

make

cc -O3 -lbz2    bsdiff.c   -o bsdiff

cc -O3 -lbz2    bspatch.c   -o bspatch

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


解决方法需要修改bspatch.c的代码去下载这个文件 http://download.csdn.net/detail/u012629497/9455482

只想$make

$ls

Makefile bsdiff.1 bspatch bspatch.c

bsdiff bsdiff.c bspatch.1

3.生成差异包
    ./bsdiff v1.0.apk v2.0.apk diff.patch 生成的是diff.path差异包
4.合成v2.0_diff_patch.apk
    ./bspatch v1.0.apk v2.0_diff_patch.apk ./diff.patch 
v2.0_diff_patch.apk就是完成后的新包
5.MD5 校验 

 $md5 new.apk

MD5 (new.apk) = c2c9ba7af42082591bc1159ee4758f1a

md5 v1.1patch.apk 

MD5 (v1.1patch.apk) = c2c9ba7af42082591bc1159ee4758f1a

6.sha1 校验

$ shasum new.apk

236459e3dbd7a9665fa4d2e3afeeecb729a6fccb  new.apk

$ shasum v1.1patch.apk 

236459e3dbd7a9665fa4d2e3afeeecb729a6fccb  v1.1patch.apk


下篇更新手机上直接合成安装

谁让今天是3.8妇女节啊






展开阅读全文

没有更多推荐了,返回首页