porting libcurl on android with ssl support

后端 未结 3 741
Happy的楠姐
Happy的楠姐 2020-12-09 01:03

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.

相关标签:
3条回答
  • 2020-12-09 01:19

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

    0 讨论(0)
  • 2020-12-09 01:28

    I like the way to use Docker for building such static libs. There is full script here - you just run it and grab the result. Sample: https://gist.github.com/VictorLaskin/1c45245d4cdeab033956

    Such script will:

    • setup compilation tools / utils download sdk/ndk
    • create custom cross-compilation toolchain download source code for libs (zlib, openssl, curl)
    • setup environment settings for cross compilation
    • configure and make libs
    • gather output at one folder and create the way to get compiled libs

    This specific version is using latest NDK 10e and clang toolchain.

    There is post with more details here: http://vitiy.info/dockerfile-example-to-compile-libcurl-for-android-inside-docker-container/

    I hope this will help someone to not waste precious time.

    0 讨论(0)
  • 2020-12-09 01:33

    Steps for compiling libcurl.so with ssl support for android jni could be found here : http://ieroot.com/2015/03/29/1728.html

    I struggled for a week for figuring out it.

    Ask if any questions. I'll reply as soon as possible.

    0 讨论(0)
提交回复
热议问题