栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

android curl库编译(一)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

android curl库编译(一)

前言

用过Linux 都知道 curl 命令,curl 支持 DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP. 最为关键是开源.

1 下载 curl 源码 下载NDK

环境 win7 64
https://curl.se/download.html
在windows 就下载了 curl-7.80.0.zip
https://github.com/android/ndk/wiki/Unsupported-Downloads
最新都 23b 这里就下载个老版本 android-ndk-r16b-windows-x86_64.zip (以前用cocoscreator打包用这个版本)

解压curl-7.80.0.zip 创建个jni 目录 把所有文件 拷贝进去

2 创建Android.mk Application.mk curl_config.h

android.mk 内容如下
-DBUILDING_LIBCURL 一定要加

LOCAL_PATH:= $(call my-dir)
 
CFLAGS := -Wpointer-arith -Wwrite-strings -Wunused -Winline 
 -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wno-long-long 
 -Wfloat-equal -Wno-multichar -Wsign-compare -Wno-format-nonliteral 
 -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement 
 -Wno-system-headers -DHAVE_CONFIG_H -DBUILDING_LIBCURL
 
include $(CLEAR_VARS)
include $(LOCAL_PATH)/lib/Makefile.inc
 
LOCAL_SRC_FILES := $(addprefix lib/,$(CSOURCES))
LOCAL_CFLAGS += $(CFLAGS)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include/ $(LOCAL_PATH)/lib
 
LOCAL_COPY_HEADERS_TO := libcurl
LOCAL_COPY_HEADERS := $(addprefix include/curl/,$(HHEADERS))
 
LOCAL_MODULE:= libcurl
 
include $(BUILD_SHARED_LIBRARY)

Application.mk 内容如下
ARMv5 就不用支持了,这个太 老了,除非你要在很老很老的机器上跑,v9都出来,以后机子一般都不支持32位了

#CPU架构	ABI	
#ARMv5	armeabi	32位,从2010年
#ARMv7	armeabi-v7a	32位,从2010年
#x86	x86	32位,从2011年
#MIPS	mips	32位,从2012年
#ARMv8	arm64-v8a	64位,从2014年
#MIPS64	mips64	64位,从2014年
#x86_64	x86_64	64位,从2014年
#APP_ABI := armeabi,armeabi-v7a,x86,mips,arm64-v8a,mips64,x86_64
#APP_ABI := all    #直接生成所有的版本

APP_PLATFORM = android-23
APP_ABI := armeabi-v7a,arm64-v8a,x86,x86_64
APP_STL := stlport_static
APP_CPPFLAGS := -fexceptions -frtti  

curl_config.h ./configure配置环境生成curl_config.h
修改内容如下 (直接拷贝这个文件内容省事也不用去./configure) 放到lib目录下

#ifndef HEADER_CURL_CONFIG_H
#define HEADER_CURL_CONFIG_H
//eh modify for android


 


 


 


 


 


 


 


 

#define CURL_DISABLE_FTP 1
 


 

#define CURL_DISABLE_IMAP 1
 

#define CURL_DISABLE_LDAP 1
 

#define CURL_DISABLE_LDAPS 1
 

#define CURL_DISABLE_POP3 1
 


 

#define CURL_DISABLE_RTSP 1
 

#define CURL_DISABLE_SMTP 1
 

#define CURL_DISABLE_TELNET 1
 

#define CURL_DISABLE_TFTP 1
 


 


 


 


 


 


 


 


 

#define GETNAMEINFO_QUAL_ARG1 const
 

#define GETNAMEINFO_TYPE_ARG1 struct sockaddr *
 

#define GETNAMEINFO_TYPE_ARG2 socklen_t
 

#define GETNAMEINFO_TYPE_ARG46 size_t
 

#define GETNAMEINFO_TYPE_ARG7 int
 


 


 

#define HAVE_ALARM 1
 

#define HAVE_ALLOCA_H 1
 

#define HAVE_ARPA_INET_H 1
 


 

#define HAVE_ASSERT_H 1
 

#define HAVE_baseNAME 1
 

#define HAVE_BOOL_T 1
 

#define HAVE_CLOCK_GETTIME_MONOTONIC 1
 


 


 

#define HAVE_CONNECT 1
 


 


 


 

#define HAVE_DLFCN_H 1
 


 


 

#define HAVE_ERRNO_H 1
 


 

#define HAVE_FCNTL 1
 

#define HAVE_FCNTL_H 1
 

#define HAVE_FCNTL_O_NONBLOCK 1
 

#define HAVE_FDOPEN 1
 

#define HAVE_FORK 1
 

#define HAVE_FREEADDRINFO 1
 


 

#define HAVE_FTRUNCATE 1
 

#define HAVE_GETADDRINFO 1
 

#define HAVE_GETADDRINFO_THREADSAFE 1
 

#define HAVE_GETEUID 1
 

#define HAVE_GETHOSTBYADDR 1
 


 


 


 


 

#define HAVE_GETHOSTBYNAME 1
 

#define HAVE_GETHOSTBYNAME_R 1
 


 


 

#define HAVE_GETHOSTBYNAME_R_6 1
 

#define HAVE_GETHOSTNAME 1
 


 

#define HAVE_GETNAMEINFO 1
 


 

#define HAVE_GETPPID 1
 

#define HAVE_GETPROTOBYNAME 1
 

#define HAVE_GETPWUID 1
 

#define HAVE_GETRLIMIT 1
 


 

#define HAVE_GETTIMEOFDAY 1
 


 

#define HAVE_GMTIME_R 1
 


 


 


 


 


 


 


 


 


 


 


 

#define HAVE_INET_ADDR 1
 


 


 


 

#define HAVE_INET_NTOP 1
 

#define HAVE_INET_PTON 1
 

#define HAVE_INTTYPES_H 1
 

#define HAVE_IOCTL 1
 


 


 


 


 

#define HAVE_IOCTL_FIONBIO 1
 

#define HAVE_IOCTL_SIOCGIFADDR 1
 


 


 


 


 


 


 


 


 


 


 

#define HAVE_LIBGEN_H 1
 


 


 


 


 


 


 


 


 

#define HAVE_LIMITS_H 1
 

#define HAVE_LL 1
 

#define HAVE_LOCALE_H 1
 

#define HAVE_LOCALTIME_R 1
 

#define HAVE_LONGLONG 1
 

#define HAVE_MALLOC_H 1
 

#define HAVE_MEMORY_H 1
 

#define HAVE_MEMRCHR 1
 

#define HAVE_MSG_NOSIGNAL 1
 

#define HAVE_NETDB_H 1
 

#define HAVE_NETINET_IN_H 1
 

#define HAVE_NETINET_TCP_H 1
 

#define HAVE_NET_IF_H 1
 


 


 


 


 


 


 


 


 


 


 


 

#define HAVE_PERROR 1
 

#define HAVE_PIPE 1
 


 

#define HAVE_POLL 1
 

#define HAVE_POLL_FINE 1
 

#define HAVE_POLL_H 1
 

#define HAVE_POSIX_STRERROR_R 1
 

#define HAVE_PWD_H 1
 


 


 


 

#define HAVE_RECV 1
 

#define HAVE_RECVFROM 1
 


 

#define HAVE_SELECT 1
 

#define HAVE_SEND 1
 

#define HAVE_SETJMP_H 1
 

#define HAVE_SETLOCALE 1
 


 

#define HAVE_SETRLIMIT 1
 

#define HAVE_SETSOCKOPT 1
 


 

#define HAVE_SGTTY_H 1
 

#define HAVE_SIGACTION 1
 

#define HAVE_SIGINTERRUPT 1
 


 

#define HAVE_SIGNAL_H 1
 

#define HAVE_SIGSETJMP 1
 

#define HAVE_SIG_ATOMIC_T 1
 


 


 

#define HAVE_SOCKET 1
 


 


 


 


 

#define HAVE_STDBOOL_H 1
 

#define HAVE_STDINT_H 1
 

#define HAVE_STDIO_H 1
 

#define HAVE_STDLIB_H 1
 

#define HAVE_STRCASECMP 1
 

#define HAVE_STRCASESTR 1
 


 

#define HAVE_STRDUP 1
 

#define HAVE_STRERROR_R 1
 


 

#define HAVE_STRINGS_H 1
 

#define HAVE_STRING_H 1
 

#define HAVE_STRLCAT 1
 


 

#define HAVE_STRNCASECMP 1
 


 


 


 

#define HAVE_STRSTR 1
 

#define HAVE_STRTOK_R 1
 

#define HAVE_STRTOLL 1
 

#define HAVE_STRUCT_SOCKADDR_STORAGE 1
 

#define HAVE_STRUCT_TIMeval 1
 


 

#define HAVE_SYS_IOCTL_H 1
 

#define HAVE_SYS_PARAM_H 1
 

#define HAVE_SYS_POLL_H 1
 

#define HAVE_SYS_RESOURCE_H 1
 

#define HAVE_SYS_SELECT_H 1
 

#define HAVE_SYS_SOCKET_H 1
 


 

#define HAVE_SYS_STAT_H 1
 

#define HAVE_SYS_TIME_H 1
 

#define HAVE_SYS_TYPES_H 1
 

#define HAVE_SYS_UIO_H 1
 

#define HAVE_SYS_UN_H 1
 

#define HAVE_SYS_UTIME_H 1
 

#define HAVE_TERMIOS_H 1
 


 

#define HAVE_TIME_H 1
 


 


 

#define HAVE_UNAME 1
 

#define HAVE_UNISTD_H 1
 

#define HAVE_UTIME 1
 

#define HAVE_UTIME_H 1
 

#define HAVE_VARIADIC_MACROS_C99 1
 

#define HAVE_VARIADIC_MACROS_GCC 1
 


 


 


 


 


 


 

#define HAVE_WRITEV 1
 


 


 


 

#define LT_OBJDIR ".libs/"
 


 


 


 


 


 


 

#define OS "arm-unknown-linux-gnu"
 

#define PACKAGE "curl"
 

#define PACKAGE_BUGREPORT "a suitable curl mailing list => http://curl.haxx.se/mail/"
 

#define PACKAGE_NAME "curl"
 

#define PACKAGE_STRING "curl -"
 

#define PACKAGE_TARNAME "curl"
 


 

#define PACKAGE_VERSION "-"
 


 


 


 


 


 


 


 


 


 


 


 

#define RECV_TYPE_ARG1 int
 

#define RECV_TYPE_ARG2 void *
 

#define RECV_TYPE_ARG3 size_t
 

#define RECV_TYPE_ARG4 unsigned int
 

#define RECV_TYPE_RETV ssize_t
 

#define RETSIGTYPE void
 

#define SELECT_QUAL_ARG5 
 

#define SELECT_TYPE_ARG1 int
 

#define SELECT_TYPE_ARG234 fd_set *
 

#define SELECT_TYPE_ARG5 struct timeval *
 

#define SELECT_TYPE_RETV int
 

#define SEND_QUAL_ARG2 const
 

#define SEND_TYPE_ARG1 int
 

#define SEND_TYPE_ARG2 void *
 

#define SEND_TYPE_ARG3 size_t
 

#define SEND_TYPE_ARG4 unsigned int
 

#define SEND_TYPE_RETV ssize_t
 

#define SIZEOF_INT 4
 

#define SIZEOF_LONG 4
 

#define SIZEOF_OFF_T 4
 

#define SIZEOF_SHORT 2
 

#define SIZEOF_SIZE_T 4
 

#define SIZEOF_TIME_T 4
 

#define SIZEOF_VOIDP 4
 

#define STDC_HEADERS 1
 

#define STRERROR_R_TYPE_ARG3 size_t
 

#define TIME_WITH_SYS_TIME 1
 


 


 


 


 


 


 


 


 


 


 


 

#define VERSION "7.47.1"
 


 

#ifndef _ALL_SOURCE

#endif
 


 


 


 


 

#ifndef __cplusplus

#endif
 


 


#endif 
3 编译libcurl.so

3.1 修改 http_chunks.h line32
原定义 #define CHUNK_MAXNUM_LEN (SIZEOF_CURL_OFF_T * 2)
SIZEOF_CURL_OFF_T 编译时找不到,搜了相关文件也没有,所有手动修改了
CURL_TYPEOF_CURL_OFF_T 在 include/system.h 有定义
看意思 For 64 bit curl_off_t we support 16 digits. For 32 bit, 8 digits 跟手动定义的一样

#define CHUNK_MAXNUM_LEN (sizeof(CURL_TYPEOF_CURL_OFF_T) *2 )  //eh modify (SIZEOF_CURL_OFF_T * 2)

3.2 修改Android.mk
-DBUILDING_LIBCURL 这个一定要加 ,上面 mk文件里已经加了,为什么呢,直接上图
自己看 easy.c easy.h 函数定义

3.3 编译so
ndk-build 这里因为ndk-build 所在目录没放到系统path 里,所以


4 编译好的SO 库链接地址

https://download.csdn.net/download/yunteng521/61669865

5 增加SSL 留后续补上 参考
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/658688.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号