zoukankan      html  css  js  c++  java
  • Android 增量更新

    在上一篇文章中提到如何生成更新包,不明白的在进入http://www.cnblogs.com/lping/p/5833090.html查看

    下载需要使用的bzip

    http://www.bzip.org/downloads.html

    拷贝源码到android studio工程的jni目录里,如果不明白jni的童鞋自行查阅Google

    生成java Patch工具类

    package com.github.liuping123.bspatch.util;
    
    /**
     * 类说明: 	APK Patch工具类
     */
    public class PatchUtils {
        static {
            System.loadLibrary("bspatch");
        }
    
        /**
         * native方法 使用路径为oldApkPath的apk与路径为patchPath的补丁包,合成新的apk,并存储于newApkPath
         * <p>
         * 返回:0,说明操作成功
         *
         * @param oldApkPath 示例:/sdcard/old.apk
         * @param newApkPath 示例:/sdcard/new.apk
         * @param patchPath  示例:/sdcard/patch.apk
         * @return
         */
        public static native int patch(String oldApkPath, String newApkPath,
                                       String patchPath);
    }
    

      通过javah生成.h文件

    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class com_github_liuping123_bspatch_util_PatchUtils */
    
    #ifndef _Included_com_github_liuping123_bspatch_util_PatchUtils
    #define _Included_com_github_liuping123_bspatch_util_PatchUtils
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
     * Class:     com_github_liuping123_bspatch_util_PatchUtils
     * Method:    patch
     * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
     */
    JNIEXPORT jint JNICALL Java_com_github_liuping123_bspatch_util_PatchUtils_patch
      (JNIEnv *, jclass, jstring, jstring, jstring);
    
    #ifdef __cplusplus
    }
    #endif
    #endif
    

      编译生成so文件,这个根据需要生成不同平台的so

    使用
    PatchUtils.patch(老的apk,新apk目录,patch文件)
    生成新apk后调用安装
    Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse("file://" + apkPath),
                    "application/vnd.android.package-archive");
            context.startActivity(intent);
    

      一切OK了

    我生成了jcenter和maven库,so支持所有平台,可以下载源码自己编译

    android studio使用maven
    
    repositories {
        maven {
            url 'https://dl.bintray.com/ping/maven/'
        }
    }
    
    dependencies {
        ...
        compile 'com.github.liuping123.bspatch:bspatchlibrary:0.0.4@aar'
    }
    
    android studio使用jcenter
    
    compile 'com.github.liuping123.bspatch:bspatchlibrary:0.0.4'

    Github地址:

    https://github.com/liuping123/BsPatchLib/

  • 相关阅读:
    caffe:使用C++来提取任意一张图片的特征(从内存读取数据)
    python:控制鼠标和键盘
    .dll 文件编写和使用
    python:打包成exe程序
    python:小乌龟turtle
    python:input()和raw_input()
    C++:哈希
    C++:线程(std::thread)
    GitHub:Git的使用
    链表
  • 原文地址:https://www.cnblogs.com/lping/p/5833417.html
Copyright © 2011-2022 走看看