How to use openSSL library in ANDROID application

I am trying to embed the openssl library in an Android application using the Android NDK, but I don’t know how to use this particular library, and so please, anyone can tell me how to use this, please send the source code for my link ... ....

Connected:

How to create OpenSSL on Android / Linux?

+7
android android-ndk native openssl jni java-native-interface
source share
2 answers

You tried this, its standalone openssl build, which is included in Android: https://github.com/fries/android-external-openssl/blob/master/README.android

+3
source share

There are some tips for using OpenSSL with Android:

  1. You must create OpenSSL libraries using the NDK tools, otherwise they will not be compatible with the NDK. Compiling the latest version of 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 assumed that these commands are executed in the OpenSSL source directory.

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

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

    and enable them in the main Android.mk:

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

    and probably add

     include $(CLEAR_VARS) 

    after that to avoid mistakes. Libraries will be hosted in libs/armabi and .apk .

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

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

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

    If you use the C ++ compiler, you may get a "vague references" error in your C functions. Use extern "C" {} to avoid this (see "C ++ Name Distortion" for more information).

  4. Finally, make sure that the manifest has network permission.

+2
source share

All Articles