Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndk-build编译miniunz #21

Open
chenpengcong opened this issue Sep 6, 2018 · 0 comments
Open

ndk-build编译miniunz #21

chenpengcong opened this issue Sep 6, 2018 · 0 comments

Comments

@chenpengcong
Copy link
Owner

本文介绍如何移植zlib/contrib/minizip的解压功能到Android平台,并提供相应的Demo源码工程

minizip依赖于zlib库,而Android官网中介绍从Android API level 3开始就提供了ZLib compression library,使用时在Android.mk中添加如下行LOCAL_LDLIBS := -lz,所以我们不需要再交叉编译出Android平台的zlib,直接将minizip的源文件集成到我们的工程中,最后编译整个工程代码。

以下是contrib/minizip/Makefile的部分内容

UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a

miniunz:  $(UNZ_OBJS)
	$(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)

从中可以看出解压功能需要以下几个.c文件

  • ioapi.c
  • miniunz.c
  • unzip.c

查看.c文件需要的头文件是

  • ioapi.h
  • zip.h
  • unzip.h

将这6个文件复制到JNI目录下,简单修改下/contrib/minizip/miniunz.c的main函数即可完成解压功能,详见Demo源码工程中miniunz.c的unzip函数

执行ndk-build时会报如下错,原因是该源码没有针对Android平台定义以下宏

/jni/ioapi.c:127: error: undefined reference to 'fopen64'
/jni/ioapi.c:157: error: undefined reference to 'ftello64'
/jni/ioapi.c:203: error: undefined reference to 'fseeko64'
/jni/miniunz.c:380: error: undefined reference to 'fopen64'
/jni/miniunz.c:411: error: undefined reference to 'fopen64'
/jni/miniunz.c:420: error: undefined reference to 'fopen64'

修改contrib/minizip/ioapi.h, 增加以下宏定义即可,参考zlib-ng/minizip-ng#137

#ifdef __ANDROID__
  #define fopen64 fopen
  #ifdef __USE_FILE_OFFSET64
    #define ftello64 ftello
    #define fseeko64 fseeko
  #else
    #define ftello64 ftell
    #define fseeko64 fseek
  #endif
#endif

修改后执行$ ndk-build,完成

@chenpengcong chenpengcong changed the title ndk-build编译miniunz.md ndk-build编译miniunz Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant