星期三, 九月 11, 2013

7zip lzma 移植到Android ndk

1) 下载LZMA-SDK源码包,下载地址:http://www.7-zip.org/sdk.html,当前最新版本是9.20,即lzma920.tar.bz2包;

2) 解压:把源码包的程序文件解压到文件夹:lzma920中;

3) 解压后,建议先查看下其中的说明文件:7zC.txt和lzma.txt两文件;

4) 进入目录:lzma920/C/Util/7z,可以看到其中有两个makefile文件:makefile和makefile.gcc,因为是在linux下,所以用makefile.gcc这个makefile文件;

5.lzma920目录下新建jni目录
将 lzma920\C\目录下所有c和.h文件复制到jni目录下,不包含util子目录
6.在jni目录下建立Android.mk文件,包含如下内容:
LOCAL_PATH:= $(call my-dir)
#LOCAL_CXX := $(CXX)
include $(CLEAR_VARS)

#LOCAL_C_INCLUDES :=
LOCAL_MODULE    :=  7zDec
LOCAL_CFLAGS    :=   -c -O2 -Wall  -flto -dM
LOCAL_SRC_FILES :=  7zAlloc.c \
7zBuf.c \
7zBuf2.c \
7zCrc.c \
7zDec.c \
7zIn.c \
7zFile.c \
7zStream.c \
7zCrcOpt.c \
CpuArch.c \
LzmaDec.c \
Lzma2Dec.c \
Bra.c \
Bra86.c \
Bcj2.c \
Ppmd7.c \
Ppmd7Dec.c


LOCAL_LDLIBS    := -llog
##LOCAL_ALLOW_UNDEFINED_SYMBOLS := true

include $(BUILD_SHARED_LIBRARY)

在lzma920目录下执行ndk-build.cmd命令

此时出现一些类型没有定义错误,可以在types.h中加入如下申明,
重新编译即可.


Types.h

//port start
typedef void *PVOID,*LPVOID;
typedef void *HANDLE;
typedef unsigned long DWORD;
/*WINNT.H*/
typedef long LONG;
typedef unsigned short WORD;

typedef struct _LIST_ENTRY {
    struct _LIST_ENTRY *Flink;
    struct _LIST_ENTRY *Blink;
} LIST_ENTRY,*PLIST_ENTRY;
typedef struct _CRITICAL_SECTION_DEBUG {
    WORD Type;
    WORD CreatorBackTraceIndex;
    struct _CRITICAL_SECTION *CriticalSection;
    LIST_ENTRY ProcessLocksList;
    DWORD EntryCount;
    DWORD ContentionCount;
    DWORD Spare [2];
} CRITICAL_SECTION_DEBUG,*PCRITICAL_SECTION_DEBUG;

typedef struct _CRITICAL_SECTION {
    PCRITICAL_SECTION_DEBUG DebugInfo;
    LONG LockCount;
    LONG RecursionCount;
    HANDLE OwningThread;
    HANDLE LockSemaphore;
    DWORD SpinCount;
} CRITICAL_SECTION;

//port over