最近做项目用到curl库
由于是使用curl库的老版本(v 1.52 ),不支持https,同时还不支持其他的一些参数设置,所以考虑升级到最新版本
先说一下环境
Windows 系统下安装了ndk
以前已经在jni目录存在老的版本代码
网上找了很多教程都使用linux编译,然后在linux里面还要安装ndk,有点复杂
所以还是要从源码下手
仔细看了一下源码里面的目录,其实需要的一个是头文件,一个是库的源码(如下图)
我直接报lib目录拷贝到jni, 并且改名为curl
修改curl_config.h(支持https,该处网上资料很多,这里就不提了)
拷贝头文件
要想在win的ndk里面编译Android的库,必须要有Android.mk才行
查找源码,发现一个现成的Android.mk
打开Android.mk看到如下内容(需要修改)
LOCAL_PATH:= $(call my-dir) common_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 ######################### # Build the libcurl library include $(CLEAR_VARS) include $(LOCAL_PATH)/Makefile.inc CURL_HEADERS := curl.h system.h curlver.h easy.h mprintf.h multi.h stdcheaders.h typecheck-gcc.h LOCAL_SRC_FILES := $($(CSOURCES)) LOCAL_C_INCLUDES += $(LOCAL_PATH)/include/ LOCAL_CFLAGS += $(common_CFLAGS) LOCAL_COPY_HEADERS_TO := libcurl/curl LOCAL_COPY_HEADERS := $(addprefix include/curl/,$(CURL_HEADERS)) LOCAL_MODULE:= libcurl LOCAL_MODULE_TAGS := optional # Copy the licence to a place where Android will find it. # Actually, this doesn't quite work because the build system searches # for NOTICE files before it gets to this point, so it will only be seen # on subsequent builds. ALL_PREBUILT += $(LOCAL_PATH)/NOTICE $(LOCAL_PATH)/NOTICE: $(LOCAL_PATH)/COPYING | $(ACP) $(copy-file-to-target) include $(BUILD_STATIC_LIBRARY) ######################### # Build the curl binary #include $(CLEAR_VARS) #include $(LOCAL_PATH)/Makefile.inc #LOCAL_SRC_FILES := $(addprefix src/,$(CURL_CFILES)) #LOCAL_MODULE := curl #LOCAL_MODULE_TAGS := optional #LOCAL_STATIC_LIBRARIES := libcurl #LOCAL_SYSTEM_SHARED_LIBRARIES := libc #LOCAL_C_INCLUDES += $(LOCAL_PATH)/include $(LOCAL_PATH)/lib # This may also need to include $(CURLX_CFILES) in order to correctly link # if libcurl is changed to be built as a dynamic library #LOCAL_CFLAGS += $(common_CFLAGS) #include $(BUILD_EXECUTABLE)
不得不说curl官方太贴心了
Build the libcurl library,不就是使用库的时候的编译吗
Build the curl binary 编译可执行文件的配置
所以直接把Build the curl binary 下面的内容禁止掉,保留Build the libcurl library
修改如下地方
尝试ndk-build,一下子通过
参考资料
https://fucknmb.com/2017/05/24/CURL-NDK%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91/?__cf_chl_captcha_tk__=91d02612e32fbaa7e5018ab39b3fd0ee4cbe08d2-1604991098-0-ATpQCNWhCFOS5nja3BB7qfIYTI9qpo7oOYld9kCwWWGVk2Vkm1O-TM-TrGyesI2NZupcyC5euRZfQWm3ydQP-bHLXD8OTbNy8FfIt0eHiDBMoGye-h8hxMg4NEOkXcLohOSmXzhc8eKkrYKF0pO3EuyOGJyclyYSrr_2WJIX8EO65omSgJz3KKqUUyopMo1mHeOO-uuSM-fiYMhUGxhsyf8IsEdoktBOthGJnHh8wAK75rHn5_JbdKGQA3N901ttol3O4xDARm6FrOfOFkTgFAFT_QoQed56qUbqWCBP4g4VPGL5r5gev6N8G70z4-Dr9GMvlY6LjKyvSf4Q7UAUfSffquDWNuk3m2SrCrKngkf9yXqVCLyHHuzb0O4ifFvCGZPJDGQVaKptceb1wxrxYMXKlRfty3H-RQcE7r8ieTL-8v3iT0F19BX01jOsT5clQICLba99k6OykuJy-k9Ua0SYqiZD2q_LetStlwR-HGdXbphSXLEZTw4VOCWwupsfNRYcxAe3xjbuRWDHOXfIt_u4h9xYdzHZhArbH6IMnuwJRg4Bqxo-7LEzaFADvpGdXg
https://blog.csdn.net/cnhua57inyu/article/details/41693661
https://www.itread01.com/content/1546390803.html?__cf_chl_captcha_tk__=8a8720aa46ae473b38ad77cfd7773aa9d49a26ee-1604980085-0-AbE4CLGvqOvstT2ZDNQzmAFVVC5TUahrxvl8MmfXKPEA48dHBWF02xh4AlvgHa-u2dZA8P21Sq6PGIS1dJYL_muUNHqbvwlQa63H8TsKX4yUlWV3AoD46yWih7Wrd7nM5pFpakqgQT6i_oytVF_FPFQVMg3qeokSJYPpOhpbniBKO4tYBQ7XjuioBLbJbhDdOm1d2m4AaTuUGsbUM4UuFfL6Y3ubyOUYYnv7lBk8zZi5yakezqREgv5aoWzYawwaRyY0NC7yqQbDQC4lHPReXdhjXUl7lqE0wKtNo4bX2mIcEyjAHPJQpgf-KKK_szmljtQqc4kNUCaf_ReJlRcfkdEFpCVV5f1KC4P4jgcOxZB_CWmno9SR8tbY9gy-ELVgiZowjjpdYbbqzOOofnMTI_H7rLoYbi_mYu641RUXXfSWhzYSi_6v64yJGxUpOy9I3SQZhtE5tL2BVCPvbbrCd-ZZHLYZrC6tUs7a6j7Wgck9awzIlmanElmIdOt515jSh2Dsh8rfENByl9aYGdF6YCE