openSSL using Android's NDK problems

≯℡__Kan透↙ 提交于 2019-11-28 09:31:56

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 :)

@Tancho

I made the change to line __gmsl:512 that you mentioned. Whilst it allowed OpenSSL to compile it also breaks the building of executables by $(BUILD_EXECUTABLE). Before the change my simple hello world application compiles and runs, but after the change it compiles but running it on my Nexus results in a seg fault.

Revert the change and all is well again. I don't know how to fix this, I don't really know what that line does, but this is just a little warning to anybody making that change.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!