4 |
5 | | library | version | platform support | arch support | pull commit |
6 |
7 | | openssl | 1.1.0f | ios | armv7s armv7 i386 x86_64 arm64 | aae1672 |
8 | | | android | armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mips64 | aae1672 |
9 | | curl | 7.53.1 | ios | armv7s armv7 i386 x86_64 arm64 | aae1672 |
10 | | | android | armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mips64 | aae1672 |
11 |
12 |
13 | ## English
14 |
15 | ## Downloads
16 |
17 | If you do not want to build it by yourself, you could download our prebuilt library from [there](https://github.com/leenjewel/openssl_for_ios_and_android/releases/tag/20170105)
18 |
19 | Android prebuilt library [download from here!!!](https://github.com/leenjewel/openssl_for_ios_and_android/releases/tag/android_openssl-1.1.0f_curl-7.54.1)
20 |
21 | ## OpenSSL Version
22 |
23 | This a static library compile from openssl and cURL for iOS and Android.
24 |
25 | - ~~[openssl-1.0.2c.tar.gz](https://www.openssl.org/source/openssl-1.0.2c.tar.gz)~~
26 | - [openssl-1.1.0f.tar.gz](https://www.openssl.org/source/openssl-1.1.0f.tar.gz)
27 | - [https://github.com/openssl/openssl](https://github.com/openssl/openssl)
28 |
29 | ## cURL Version
30 |
31 | - ~~[curl-7.47.1.tar.gz](https://curl.haxx.se/download/curl-7.47.1.tar.gz)~~
32 | - [curl-7.53.1.tar.gz](https://curl.haxx.se/download/curl-7.53.1.tar.gz)
33 | - [https://github.com/curl/curl](https://github.com/curl/curl)
34 |
35 | ## Android NDK Version
36 |
37 | - ~~[android-ndk-r13b](https://dl.google.com/android/repository/android-ndk-r13b-darwin-x86_64.zip)~~
38 | - [android-ndk-r14b](https://dl.google.com/android/repository/android-ndk-r14b-darwin-x86_64.zip)
39 | - ~~android-ndk-r15 (**Do not try to build use 15 It will fail**)~~
40 |
41 | ## How to build
42 |
43 | ### For iOS
44 |
45 | Copy `openssl-1.1.0f.tar.gz` to `tools` file folder and run
46 |
47 | ```
48 | cd tools
49 | sh ./build-openssl4ios.sh
50 | ```
51 |
52 | Copy `curl-7.53.1.tar.gz` to `tools` file folder and run
53 |
54 | ```
55 | cd tools
56 | sh ./build-curl4ios.sh
57 | ```
58 |
59 | ### For Android
60 |
61 | Set ENV `NDK_ROOT`
62 |
63 |
64 | ```
65 | cd tools
66 | sh ./build-openssl4android.sh
67 | ```
68 |
69 | You could build it with ABI like
70 |
71 | ```
72 | cd tools
73 | sh ./build-openssl4android.sh android # for armeabi
74 | sh ./build-openssl4android.sh android-armeabi #for armeabi-v7a
75 | sh ./build-openssl4android.sh android64-arm64 #for arm64_v8a
76 | sh ./build-openssl4android.sh android-x86 #for x86
77 | sh ./build-openssl4android.sh android64 #for x86_64
78 | sh ./build-openssl4android.sh mips #for mips
79 | sh ./build-openssl4android.sh mips64 #for mips64
80 | ```
81 |
82 | > **You must build openssl first**
83 | >
84 | > **else cURL HTTPS is disable (without ssl)**
85 |
86 | OpenSSL for Android is build with `libz` support using dynamic
87 | link. `libz` is publically provided by Android system.
88 |
89 | ```
90 | sh ./build-curl4android.sh
91 | ```
92 |
93 | You could build it with ABI like
94 |
95 | ```
96 | cd tools
97 | sh ./build-curl4android.sh android # for armeabi
98 | sh ./build-curl4android.sh android-armv7 #for armeabi-v7a
99 | sh ./build-curl4android.sh android64-arm64 #for arm64_v8a
100 | sh ./build-curl4android.sh android-x86 #for x86
101 | sh ./build-curl4android.sh android-x86_64 #for x86_64
102 | sh ./build-curl4android.sh mips #for mips
103 | sh ./build-curl4android.sh mips64 #for mips64
104 | ```
105 |
106 | ## How to use
107 |
108 | ### For iOS
109 |
110 | Copy `lib/libcrypto.a` and `lib/libssl.a` and `lib/libcurl.a` to your project.
111 |
112 | Copy `include/openssl` folder and `include/curl` folder to your project.
113 |
114 | Add `libcrypto.a` and `libssl.a` and `libcurl.a` to `Frameworks` group and add them to `[Build Phases] ====> [Link Binary With Libraries]`.
115 |
116 | Add openssl include path and curl include path to your `[Build Settings] ====> [User Header Search Paths]`
117 |
118 | ### About "\_\_curl\_rule\_01\_\_ declared as an array with a negative size" problem
119 |
120 | When you build cURL for arm64 you will get this error.
121 |
122 | You need to change `curlbuild.h` from :
123 |
124 | ```c
125 | #define CURL_SIZEOF_LONG 4
126 | ```
127 |
128 | to :
129 |
130 | ```c
131 | #ifdef __LP64__
132 | #define CURL_SIZEOF_LONG 8
133 | #else
134 | #define CURL_SIZEOF_LONG 4
135 | #endif
136 | ```
137 |
138 | ### For Android
139 |
140 | Copy `lib/armeabi` folder and `lib/armeabi-v7a` folder and `lib/x86` to your android project `libs` folder.
141 |
142 | Copy `include/openssl` folder and `include/curl` to your android project.
143 |
144 | #### Android Makefile
145 | Add openssl include path to `jni/Android.mk`.
146 |
147 | ```
148 | #Android.mk
149 |
150 | include $(CLEAR_VARS)
151 |
152 | LOCAL_MODULE := curl
153 | LOCAL_SRC_FILES := Your cURL Library Path/$(TARGET_ARCH_ABI)/libcurl.a
154 | include $(PREBUILT_STATIC_LIBRARY)
155 |
156 |
157 | LOCAL_C_INCLUDES := \
158 | $(LOCAL_PATH)/Your Openssl Include Path/openssl \
159 | $(LOCAL_PATH)/Your cURL Include Path/curl
160 |
161 | LOCAL_STATIC_LIBRARIES := libcurl
162 |
163 | LOCAL_LDLIBS := -lz
164 |
165 | ```
166 |
167 | ### CMake
168 | Define `ssl`, `crypto`, `curl` as *STATIC IMPORTED* libraries.
169 |
170 |
171 | ```
172 | add_library(crypto STATIC IMPORTED)
173 | set_target_properties(crypto
174 | PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libcrypto.a)
175 |
176 | add_library(ssl STATIC IMPORTED)
177 | set_target_properties(ssl
178 | PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libssl.a)
179 |
180 | add_library(curl STATIC IMPORTED)
181 | set_target_properties(curl
182 | PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libcurl.a)
183 | ```
184 |
185 | Then link these libraries with your target, e.g.
186 |
187 |
188 | ```
189 | target_link_libraries( # Specifies the target library.
190 | native-lib
191 |
192 | curl
193 | ssl
194 | crypto
195 | )
196 | ```
197 |
198 | ### About "libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal' " problem
199 |
200 | when you get these error
201 |
202 | ```
203 | libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal'
204 |
205 | libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr'
206 | ```
207 |
208 | You need to rebuild OpenSSL static library with NDK API level 16 or earlier
209 |
210 | If you build OpenSSL with API level 16 or earlier you may not build it for arch 64 bit only support 32 bit
211 |
212 | more information :
213 |
214 | [https://github.com/openssl/openssl/issues/988](https://github.com/openssl/openssl/issues/988)
215 |
216 | [http://stackoverflow.com/questions/37122126/whats-the-exact-significance-of-android-ndk-platform-version-compared-to-api-le](http://stackoverflow.com/questions/37122126/whats-the-exact-significance-of-android-ndk-platform-version-compared-to-api-le)
217 |
218 | ## 中文
219 |
220 | 这是一个适用于 iOS 平台和 Android 平台的 Openssl 静态链接库。基于 openssl-1.1.0f 版本编译生成。
221 |
222 | 后来又加入了适用于 iOS 平台和 Android 平台且支持 SSL 的 cURL 静态链接库。基于 curl-7.53.1 版本编译生成。
223 |
224 | > Our build script default use API 16 to build OpenSSL
225 |
226 | ## 下载
227 |
228 | 如果你不想自己构建,那么你可以使用我们已经预先构建好的版本,[请在这里下载](https://github.com/leenjewel/openssl_for_ios_and_android/releases/tag/20170105)
229 |
230 |
231 | Android 编译好的库[从这里下载!!!](https://github.com/leenjewel/openssl_for_ios_and_android/releases/tag/android_openssl-1.1.0f_curl-7.54.1)
232 |
233 |
234 | ## 在 iOS 工程中使用
235 |
236 | 将 `lib/libcrypto.a` 和 `lib/libssl.a` 还有 `lib/libcurl.a` 三个静态链接库文件拷贝到你的 iOS 工程下面合适的位置。
237 |
238 | 将 `include/openssl` 文件夹和 `include/curl` 文件夹拷贝到你的 iOS 工程下面合适的位置。注意,所有的头文件均要放置到 `openssl` 文件夹下,不要随意更改文件夹名称。
239 |
240 | 将 `libcrypto.a` 和 `libssl.a` 还有 `lib/libcurl.a` 三个静态链接库文件通过`[Build Phases] ====> [Link Binary With Libraries]`引入你的 iOS 工程。
241 |
242 | 将包含所有头文件的 `openssl` 文件夹和含有头文件的 `curl` 文件夹设置到头文件搜索路径中。即在 `[Build Settings] ====> [User Header Search Paths]` 中设置好。
243 |
244 | ### 关于 "\_\_curl\_rule\_01\_\_ declared as an array with a negative size" 的问题解决办法
245 |
246 | 当你在 iOS 的 arm64 架构环境下编译 cURL 静态库时会遇到这个问题。解决的办法是修改 `curlbuild.h` 头文件,将下面这行 :
247 |
248 | ```c
249 | #define CURL_SIZEOF_LONG 4
250 | ```
251 |
252 | 改成 :
253 |
254 | ```c
255 | #ifdef __LP64__
256 | #define CURL_SIZEOF_LONG 8
257 | #else
258 | #define CURL_SIZEOF_LONG 4
259 | #endif
260 | ```
261 |
262 | ## 在 Android 工程中使用
263 |
264 | 将 `lib/armeabi` 和 `lib/armeabi-v7a` 还有 `lib/x86` 文件夹拷贝到你的 Android 工程下面的 `libs` 文件夹中。
265 |
266 | 将 `include/openssl` 文件夹和 `include/curl` 文件夹拷贝到你的 Android 工程下面合适的位置。注意,所有的头文件均要放置到 `openssl` 文件夹下,不要随意更改文件夹名称。
267 |
268 | ### Android Makefile 系统
269 |
270 | 修改 `jni/Android.mk` 文件,将头文件路径加入到搜索路径中,例如:
271 |
272 | ```
273 | # Android.mk
274 |
275 | include $(CLEAR_VARS)
276 |
277 | LOCAL_MODULE := curl
278 | LOCAL_SRC_FILES := Your cURL Library Path/$(TARGET_ARCH_ABI)/libcurl.a
279 | include $(PREBUILT_STATIC_LIBRARY)
280 |
281 |
282 | include $(CLEAR_VARS)
283 |
284 | LOCAL_MODULE := curl
285 | LOCAL_SRC_FILES := Your cURL Library Path/$(TARGET_ARCH_ABI)/libcurl.a
286 | include $(PREBUILT_STATIC_LIBRARY)
287 |
288 |
289 | LOCAL_C_INCLUDES := \
290 | $(LOCAL_PATH)/Your Openssl Include Path/openssl \
291 | $(LOCAL_PATH)/Your cURL Include Path/curl
292 |
293 | LOCAL_STATIC_LIBRARIES := libcurl
294 |
295 | LOCAL_LDLIBS := -lz
296 |
297 | ```
298 |
299 | ### CMake 系统
300 | 把 `ssl`, `crypto`, `curl` 定义成 *STATIC IMPORTED* 库。
301 |
302 |
303 | ```
304 | add_library(crypto STATIC IMPORTED)
305 | set_target_properties(crypto
306 | PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libcrypto.a)
307 |
308 | add_library(ssl STATIC IMPORTED)
309 | set_target_properties(ssl
310 | PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libssl.a)
311 |
312 | add_library(curl STATIC IMPORTED)
313 | set_target_properties(curl
314 | PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libcurl.a)
315 | ```
316 |
317 | 把它们和你的目标链接,如:
318 |
319 |
320 | ```
321 | target_link_libraries( # Specifies the target library.
322 | native-lib
323 |
324 | curl
325 | ssl
326 | crypto
327 | )
328 | ```
329 |
330 | ### 关于 "libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal' " 报错解决
331 |
332 | 当你将编译好的 OpenSSL 静态库链接进你的安卓工程时,可能会遇到如下报错
333 |
334 | ```
335 | libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal'
336 |
337 | libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr'
338 | ```
339 |
340 | 这时你需要使用低版本的 API 重新编译 OpenSSL 静态库,推荐使用 android-16 或以下版本的 API 来重新编译
341 |
342 | 用低版本 API 编译的副作用是你无法编译出支持 64 位架构的静态库,只能编译出支持 32 位架构的静态库
343 |
344 | 具体信息可以参考:
345 |
346 | [https://github.com/openssl/openssl/issues/988](https://github.com/openssl/openssl/issues/988)
347 |
348 | [http://stackoverflow.com/questions/37122126/whats-the-exact-significance-of-android-ndk-platform-version-compared-to-api-le](http://stackoverflow.com/questions/37122126/whats-the-exact-significance-of-android-ndk-platform-version-compared-to-api-le)
349 |
350 | > 目前我们的编译脚本默认设置已经更改为使用 API 16 编译 32 位的 OpenSSL 静态库了
351 |
352 | ## Reference / 参考资料
353 |
354 | >[《How-To-Build-openssl-For-iOS》](http://www.cvursache.com/2013/08/13/How-To-Build-openssl-For-iOS/)
355 | >
356 | >[《Compiling the latest OpenSSL for Android》](http://stackoverflow.com/questions/11929773/compiling-the-latest-openssl-for-android)
357 | >
358 | >[《在 Cocos2d-x 中使用 OpenSSL》](http://leenjewel.github.io/blog/2015/06/30/zai-cocos2d-x-zhong-shi-yong-openssl/)
359 | >
360 | >[《using curl on iOS, I am unable to link with multiple architectures, CurlchkszEQ macro failing》](http://stackoverflow.com/questions/21681954/using-curl-on-ios-i-am-unable-to-link-with-multiple-architectures-curlchkszeq)
361 | >
362 | >[《porting libcurl on android with ssl support》](http://stackoverflow.com/questions/11330180/porting-libcurl-on-android-with-ssl-support)
363 |
--------------------------------------------------------------------------------