环境:
centos android9 idea
步骤:
1.下载bsdiff
2.centos 安装
gcc
make
bzip2
bzip2-devel
命令
yum -y install gcc autoconf automake libtool make
yum -y install bzip2
yum -y install bzip2-devel
3.修改解压后bsdiff中Makefile文件.ifndef WITHOUT_MAN 和endif 缩进
4.在bsdiff中执行 make命令生成bsdiff和bspatch文件
5.生成合并差异包
生成 bsdiff oldapk_path.apk newapk_path.apk patchName.patch
合并 bspatch oldapk_path.apk newName_path.apk patch_path.patch
以上为服务端
Android端
1.ndk新建个PatchUtil.java用与调用native方法
public class PatchUtils {
private static PatchUtils instance;
static {
System.loadLibrary("update");
}
public static PatchUtils getInstance(){
if(instance==null){
instance = new PatchUtils();
}
return instance;
}
/**
* native方法 使用路径为oldApkPath的Apk与路径为patchPath的补丁包合成一个新的apk存储与newApkPath
* 返回 0 成功
* @param oldApkPath 示例:/usr/old/old.apk
function(){ //外汇代理 http://www.fx61.com/ib.html
* @param newApkPath 示例:/usr/new/new.apk
* @param patchPath 示例:/usr/patch/patch_1.patch
* @return
*/
public static native int bspatch(String oldApkPath, String newApkPath, String patchPath);
}
配置java.h 和buildOS
3.使用javah命令生成头文件,会在jni文件夹下生成com_xxx_xxx_xxx.PatchUtils.h,
4.将bsdiff文件夹下载bspatch.c导入jni文件夹
5.下载bzip2导入jni文件夹,删除除了.c和.h的其他文件
修改bspatch.c
/*-
* Copyright 2003-2005 Colin Percival
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted providing that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES O