Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use openSSL Library in the ANDROID application

i am trying to embed the openssl library in my Android application using Android NDK but i don't know how to use exactly that library and so please any one can tell me how to use that please send a source code for my reference.......

Related :

How to build OpenSSL on Android/Linux ?

like image 621
Pankaj D. Gaurshettiwar Avatar asked Jun 15 '10 15:06

Pankaj D. Gaurshettiwar


2 Answers

Have you tried this, its a standalone build of the openssl that's included in Android: https://github.com/fries/android-external-openssl/blob/master/README.android

like image 141
Hans-Christoph Steiner Avatar answered Nov 18 '22 16:11

Hans-Christoph Steiner


There are several tips about using OpenSSL with Android:

  1. It is necessary to build OpenSSL libraries using NDK tools, otherwise they will be incompatible with the NDK. Compiling the latest OpenSSL for Android

    CC=~/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc
    ./Configure android-armv7
    export ANDROID_DEV=~/android-ndk-r9//platforms/android-8/arch-arm/usr
    make build_libs
    

    It is supposed that these commands are executed in the source directory of OpenSSL.

  2. In order to use these libraries (ssl and crypto) with your own library from the NDK, you need to create additional *.mk files in jni folder. For example:

    include $(CLEAR_VARS)
    
    LOCAL_MODULE    := ssl-crypto
    LOCAL_SRC_FILES := openssl-crypto/libcrypto.so
    
    include $(PREBUILT_SHARED_LIBRARY)
    

    and include them into the main Android.mk:

    include $(LOCAL_PATH)/openssl-ssl/Android.mk
    

    and probably add

    include $(CLEAR_VARS) 
    

    after it to avoid errors. Libraries will be placed into libs/armabi and .apk.

  3. If you will encounter with could not load library ... needed by ... error then it probably means that your library has soname with a version number. AFAIK NDK is unable to work with such libraries at this moment. There is a workaround (Dalvik is looking for .so file with '.0' extension - why?):

    rpl -R -e library.so.1.1 "library.so\x00\x00\x00\x00" libs obj
    

    where rpl is a linux string replacement tool. Run this script after building and before running your application and it will remove version number from the project files. Follow the link for more information.

    If you use a C++ compiler you may get "undefined references" error in your C functions. Use extern "C" {} to avoid this (see "C++ name mangling" for more info).

  4. At last make sure that there is a network permission in the manifest.

like image 3
bartolo-otrit Avatar answered Nov 18 '22 17:11

bartolo-otrit