SSL支持在Android上移植的libcurl [英] porting libcurl on android with ssl support

查看:857
本文介绍了SSL支持在Android上移植的libcurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想端口的libcurl到Android SSL支持, 第一步是将端口不支持SSL我想,所以我开始做的卷曲。但我遇到一个问题。

因为我读的开发网站,并在Android.mk文件中,最困难的部分是第一次配置的化妆。所以我所做的是:

  1. 下载Android源码code(和编译它!因为一些中间库的需要)

  2. 下载卷曲

  3. 解包卷曲下:{} android_src /外部/卷曲

  4. 创建外部/卷曲文件夹中的SH文件与此内容做出了卷曲的配置脚本。

`

 导出= /家庭/用户/开发/ AOSP / 2.3.3
出口CC = $ A / prebuilt / Linux的-86 /工具链/ ARM-EABI-4.2.1 /斌/ ARM-EABI-gcc的
出口NDK = /家庭/用户/开发/工具/ SDK /安卓/ NDK
出口NDKLIBS = $ NDK /平台/ Android的-4 /弓臂/ usr / include目录
出口SYSROOT = $ A / NDK /建设/平台/ Android的-4 /弓臂
出口CPPFLAGS = -  I $ A /系统/核心/包括
出口LDFLAGS = -  1 $ A /缩小/目标/产品/通用/ OBJ / LIB / -L $ A /缩小/目标/产品/通用/系统/ lib中/ -L $ SYSROOT / usr / lib目录轮候册, - -gc截面-nostdlib -lc -lm -ldl -llog -lgcc轮候册, - 没有定义,-z,nocopyreloc -Wl,-dynamic链接器,/系统/斌/连接器-L $ NDK /输出/目标/产品/通用/ OBJ / LIB /
出口CFLAGS = -  FNO-例外-Wno-multichar -mthumb -mthumb-互通-nostdlib -lc -ldl -lm -march =的ARMv5TE -mtune =的XScale -msoft流通-mandroid -fPIC -mthumb-互通-mthumb -mlong -calls -ffunction截面-fstack,保护了-fno-short-枚举-fomit-frame-pointer的-fno严格走样-finline-上限= 64 -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DOS_ANDROID -D__NEW__ -D__SGI_STL_INTERNAL_PAIR_H -I $ SYSROOT / usr / include目录-I $ A /系统/核心/包括-I $ NDKLIBS

的./configure主机=臂EABI --with-ssl的= $ A /外部/ OpenSSL的
 

` 而输出总结为这样一句:

配置:配置打造卷曲/ libcurl的:

 卷曲的版本:7.26.0
  主机设置ARM-未知EABI
  安装preFIX:在/ usr /本地
  编译:/home/tanco/Development/AOSP/2.3.3/$p$pbuilt/linux-x86/tool​​chain/arm-eabi-4.2.1/bin/arm-eabi-gcc
  SSL支持:无(--with- {SSL,GNUTLS,NSS polarssl,cyassl,axtls})
  SSH支持:无(--with-libssh2)
  支持zlib:启用
  krb4用支持:无(--with-krb4用*)
  GSSAPI支持:无(--with-GSSAPI)
  SPNEGO支持:无(--with-SPNEGO)
  TLS-SRP支持:无(--enable-TLS-SRP)
  解析:默认(--enable-战神/ --enable-线程解析程序)
  IPv6支持:无(--enable-的IPv6)
  IDN支持:无(--with-libidn这个)
  建设libcurl的:共享=无,静态= YES
  内置手动:启用
  --libcurl选项:启用( - 禁用libcurl的选项)
  详细的错误是:启用( - 禁用详细)
  SSPI支持:无(--enable-SSPI)
  CA证书捆绑:/etc/ssl/certs/ca-certificates.crt
  CA证书路径:无
  LDAP支持:无(--enable-LDAP / --with-LDAP-LIB / --with-lber-LIB)
  LDAPS支持:无(--enable-LDAPS)
  RTSP支持:启用
  RTMP支持:无(--with-librtmp)
  协议:词典文件的FTP GOPHER HTTP IMAP POP3 SMTP RTSP TELNET TFTP

  SONAME碰撞:是的 - 警告:这个库将与SONAME建
                   号碰着由于(一个检测到的)的ABI破损。
                   见LIB / README.curl_off_t有关细节。
 

一奇怪的事情,想到的是,为什么是SSL不包含在配置,因为连接器​​显示到中间库和SSL支持的标志是所谓的,但是当我用同样的curl_config.h文件中的JNI项目之后,我为构建创建(因为它有一个独立的Andr​​oid.mk文件,它可以简单地通过解压在一个Android项目的JNI文件夹,复制在AOSP源创建配置文件并调用NDK建造编译)

让我编译,我得到:

  $ NDK建造
编译大拇指:卷曲< = url.c
在文件中包括来自/Projects/temp/testNDK/jni/lib/url.c:32:0:
/Tools/sdk/android/ndk/platforms/android-14/arch-arm/usr/include/unistd.h:在功能为getpagesize:
/Tools/sdk/android/ndk/platforms/android-14/arch-arm/usr/include/unistd.h:171:3:警告:__page_size[-Wnested-实习医生]嵌套外部声明
/Tools/sdk/android/ndk/platforms/android-14/arch-arm/usr/include/unistd.h:在函数'__getpageshift:
/Tools/sdk/android/ndk/platforms/android-14/arch-arm/usr/include/unistd.h:175:3:警告:__page_shift[-Wnested-实习医生]嵌套外部声明
/Projects/temp/testNDK/jni/lib/url.c:在顶层:
/Projects/temp/testNDK/jni/lib/url.c:57:2:错误:#ERROR我们不能编译没有插座()的支持!
使:*** [/Projects/temp/testNDK/obj/local/armeabi/objs/curl/lib/url.o]错误1
 

解决方案

下面是解决方案,更新NDK8c

一步零:下载并修复了Android NDK 我不知道怎样,但NDK有一个很有趣的缺陷,这(在我看来)不会让你编很多的东西,这样一来就能编译OpenSSL的,你需要做一个小的修复,提取ndk8c。无论您保持你的工具,然后编辑该文件: Android的NDK-R8C /建设/ G​​MSL / __ GMSL 行512: 变线

  INT_EN code = $(__ gmsl_tr1)$(单词表1,$ 1,$(__ gmsl_input_int))
 

与行

  INT_EN code = $(__ gmsl_tr1)$(单词表1,$(字$ 1)$(__ gmsl_input_int))
 

和你去好!

第一步:下载OpenSSL和编译的Andr​​oid版本: 无论是编译移植版本,发现 此处 或下载的OpenSSL的官方1.0.0c版本,然后用在github上我挂了Android的兼容版本提供的说明书编译Android版

因此​​,下一步是让在 libssl.so libcrypto.so 并把他们在NDK文件夹为方便,所以从

复制它们

  OpenSSL的文件夹/库/ armeabi /
 

 的Andr​​oid NDK,R8C /平台/ Android为8 /弓臂/ usr / lib目录
 

在编译时,你可以使用一个简单的链接器开关包括库这样 -lssl -lcrypto

第二步:把卷曲的最新源代码的 这里

中打开文档文件/安装并按照需要作出独立的工具链,并在您需要的文件夹中的步骤,再棘手的部分,我需要有Android的源$ C ​​$ C的配置继续,甚至但我有一个独立的编译OpenSSL的,您可以包含有头文件也是如此,在anycase是这样的话,你选择什么你做什么,我没有选择逃避他们,你可以去的谷歌AOSP网站和走线槽的步骤来建立和初始化环境

所以它会是这样的:

1.download,

  1. 去源$ C ​​$ C根目录并运行:

    〜:编译/ envsetup.sh;午餐1;令;

所以最后我们需要编译卷曲SSL支持,所以,

第三步

提取物卷曲到所需的文件夹 (我有禁止一切除了HTTP / S特定的愿望,以保持库小至〜300K,如果你在你的lib希望更多的协议,删除 - 禁用协议所需的协议可能意) 运行以下命令:

 使清洁

出口PATH = /选择/ ARM-Linux的androideabi-4.4.3 / bin中:$ PATH

出口LDFLAGS =\
-lssl \
-lcrypto \
-L /家庭/用户/开发/工具/ SDK /安卓/ NDK /平台/ Android为8 /弓臂/ usr / lib目录

出口CFLAGS =\
-I /家庭/用户/开发/ AOSP / 2.3.7 /系统/核心/包括\
-I /家庭/用户/开发/工具/ SDK /安卓/ NDK /平台/ Android为8 /弓臂/ usr / include目录

的./configure主机=臂的Linux androideabi \
--with-ssl的= /家庭/用户/开发/项目/ portingLibs / OpenSSL的,Android的主\
 - 禁用FTP \
 - 禁用的gopher \
 - 禁用文件\
--disable-IMAP \
 - 禁用LDAP \
 - 禁用LDAPS \
 - 禁用POP3 \
 - 禁用代理\
 - 禁用RTSP \
 - 禁用SMTP \
 - 禁用远程登录\
 - 禁用TFTP \
--without-GNUTLS \
--without-libidn这个\
--without-librtmp \
 - 禁用字典


使



请注意,在块上方,如果你不希望使用AOSP源代码,你可以切换

-I /家庭/用户/开发/ AOSP / 2.3.7 /系统/核心/包括\

与包括文件夹进行SSL分布。
 

所以最后你有: 静态的:

 卷曲7.28.1 / lib中/的.libs / libcurl.a
 

和共享的:

 卷曲7.28.1 / lib中/的.libs / libcurl.so.5.3
 

所以这是它..拿那个文件,然后进行编译:)

I am trying to port libCurl to android with SSL support, step one would be to port the curl without ssl support I guess so I started doing that. but I run into a problem.

as I read on the dev website and in the Android.mk file, the hard part is configuring the make first. so what I did is :

  1. Download Android Source code (and compile it! since some of the intermediate libs are needed)

  2. Download cURL

  3. unpack curl under : {android_src}/external/curl

  4. make the configure script for curl by creating a sh file in the external/curl folder with this content.

`

export A=/home/user/Development/AOSP/2.3.3    
export CC=$A/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gcc 
export NDK=/home/user/Development/Tools/sdk/android/ndk
export NDKLIBS=$NDK/platforms/android-4/arch-arm/usr/include
export SYSROOT=$A/ndk/build/platforms/android-4/arch-arm 
export CPPFLAGS="-I $A/system/core/include"
export LDFLAGS="-L$A/out/target/product/generic/obj/lib/ -L$A/out/target/product/generic/system/lib/-L$SYSROOT/usr/lib -Wl,--gc-sections -nostdlib -lc -lm -ldl -llog -lgcc -Wl,--no-undefined,-z,nocopyreloc -Wl,-dynamic-linker,/system/bin/linker -L$NDK/out/target/product/generic/obj/lib/" 
export CFLAGS="-fno-exceptions -Wno-multichar -mthumb -mthumb-interwork -nostdlib -lc -ldl -lm -march=armv5te -mtune=xscale -msoft-float -mandroid -fPIC -mthumb-interwork -mthumb -mlong-calls -ffunction-sections -fstack-protector  -fno-short-enums -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DOS_ANDROID -D__NEW__ -D__SGI_STL_INTERNAL_PAIR_H -I$SYSROOT/usr/include -I $A/system/core/include -I $NDKLIBS" 

./configure --host=arm-eabi --with-ssl=$A/external/openssl

` And the output summary is this one :

configure: Configured to build curl/libcurl:

  curl version:     7.26.0
  Host setup:       arm-unknown-eabi
  Install prefix:   /usr/local
  Compiler:         /home/tanco/Development/AOSP/2.3.3/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gcc
  SSL support:      no      (--with-{ssl,gnutls,nss,polarssl,cyassl,axtls} )
  SSH support:      no      (--with-libssh2)
  zlib support:     enabled
  krb4 support:     no      (--with-krb4*)
  GSSAPI support:   no      (--with-gssapi)
  SPNEGO support:   no      (--with-spnego)
  TLS-SRP support:  no      (--enable-tls-srp)
  resolver:         default (--enable-ares / --enable-threaded-resolver)
  ipv6 support:     no      (--enable-ipv6)
  IDN support:      no      (--with-libidn)
  Build libcurl:    Shared=no, Static=yes
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  SSPI support:     no      (--enable-sspi)
  ca cert bundle:   /etc/ssl/certs/ca-certificates.crt
  ca cert path:     no
  LDAP support:     no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)
  LDAPS support:    no      (--enable-ldaps)
  RTSP support:     enabled
  RTMP support:     no      (--with-librtmp)
  Protocols:        DICT FILE FTP GOPHER HTTP IMAP POP3 RTSP SMTP TELNET TFTP

  SONAME bump:     yes - WARNING: this library will be built with the SONAME
                   number bumped due to (a detected) ABI breakage.
                   See lib/README.curl_off_t for details on this.

First strange thing that comes to mind is why is SSL not included in the config since the linker shows to the intermediate libs and ssl support flag is called, but after when I use the same curl_config.h file in the jni project which I created for the build (since it has a standalone Android.mk file it can be compiled simply by unzipping in the jni folder of a android project, copying the config file created in the AOSP source and calling ndk-build)

so I compile and I get :

$ ndk-build
Compile thumb  : curl <= url.c
In file included from /Projects/temp/testNDK/jni/lib/url.c:32:0:
/Tools/sdk/android/ndk/platforms/android-14/arch-arm/usr/include/unistd.h: In function 'getpagesize':
/Tools/sdk/android/ndk/platforms/android-14/arch-arm/usr/include/unistd.h:171:3: warning: nested extern declaration of '__page_size' [-Wnested-externs]
/Tools/sdk/android/ndk/platforms/android-14/arch-arm/usr/include/unistd.h: In function '__getpageshift':
/Tools/sdk/android/ndk/platforms/android-14/arch-arm/usr/include/unistd.h:175:3: warning: nested extern declaration of '__page_shift' [-Wnested-externs]
/Projects/temp/testNDK/jni/lib/url.c: At top level:
/Projects/temp/testNDK/jni/lib/url.c:57:2: error: #error "We can't compile without socket() support!"
make: *** [/Projects/temp/testNDK/obj/local/armeabi/objs/curl/lib/url.o] Error 1

解决方案

Here is the solution, updated to NDK8c

step zero: download and fix the Android NDK I dunno how but the ndk has a very interesting flaw, which (in my oppinion) doesn't allow you to compile lot's of stuff, so to be able to compile OpenSSL you need to make a small fix, extract the ndk8c whereever you keep your tools, and then edit the file : android-ndk-r8c/build/gmsl/__gmsl line 512 : change line

int_encode = $(__gmsl_tr1)$(wordlist 1,$1,$(__gmsl_input_int))

with line

int_encode = $(__gmsl_tr1)$(wordlist 1,$(words $1),$(__gmsl_input_int))

And you're good to go!

step one : Download OpenSSL and compile for Android : either compile a ported version found here or Download the official 1.0.0c version of OpenSSL and then compile it for android using the manual provided in the github I linked for the Android compatible version

So the next step is to get the libssl.so and libcrypto.so and put the them in the NDK folder for easy access, so copy them from

openssl-folder/libs/armeabi/

to

android-ndk-r8c/platforms/android-8/arch-arm/usr/lib

this way when compiling you can include the libs using a simple linker switch -lssl -lcrypto

Step two : get Curl's latest source for here

Open the file in Docs/INSTALL and follow the steps needed to make the standalone toolchain and put in your desired folder, and then the tricky part, I needed to have android's source code for the config to continue, even though I have a standalone compiled openssl you can include the header files from there too, in anycase this is the more complicated version so you choose what you do, I did not choose to evade them so you can go to Google AOSP site and go trough the steps to build and initialize the environment.

so it would be something like :

1.download,

  1. go to root of the source code and run :

    ~: build/envsetup.sh; lunch 1; make;

So finally we need to compile curl with SSL support, so,

Step three

extract curl to the desired folder (I have a specific desire of disabling everything except http/s to keep the library as small as possible meaning about ~300k, if you want more protocols in your lib, remove the --disable-protocol for the desired protocol) run the following :

make clean

export PATH=/opt/arm-linux-androideabi-4.4.3/bin:$PATH

export LDFLAGS="\
-lssl \
-lcrypto \
-L/home/user/Development/Tools/sdk/android/ndk/platforms/android-8/arch-arm/usr/lib"

export CFLAGS="\
-I/home/user/Development/AOSP/2.3.7/system/core/include \
-I/home/user/Development/Tools/sdk/android/ndk/platforms/android-8/arch-arm/usr/include"

./configure --host=arm-linux-androideabi \
--with-ssl=/home/user/Development/Projects/portingLibs/openssl-android-master \
--disable-ftp \
--disable-gopher \
--disable-file \
--disable-imap \
--disable-ldap \
--disable-ldaps \
--disable-pop3 \
--disable-proxy \
--disable-rtsp \
--disable-smtp \
--disable-telnet \
--disable-tftp \
--without-gnutls \
--without-libidn \
--without-librtmp \
--disable-dict


make



Note that in the block above, if you don't want to use the AOSP source, you could switch 

-I/home/user/Development/AOSP/2.3.7/system/core/include \

with the include folder for your ssl distribution.

So finally you have : static :

curl-7.28.1/lib/.libs/libcurl.a

and shared :

curl-7.28.1/lib/.libs/libcurl.so.5.3

So that's it.. take the file, and compile away :)

这篇关于SSL支持在Android上移植的libcurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆