简体   繁体   English

如何在ANDROID应用程序中使用openSSL库

[英]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....... 我正在尝试使用Android NDK在我的Android应用程序中嵌入openssl库,但我不知道如何使用该库,所以请任何人都可以告诉我如何使用它请发送源代码供我参考... ....

Related : 相关:

How to build OpenSSL on Android/Linux ? 如何在Android / Linux上构建OpenSSL?

你试过这个吗,它是一个包含在Android中的openssl的独立版本: https//github.com/fries/android-external-openssl/blob/master/README.android

There are several tips about using OpenSSL with Android: 关于在Android上使用OpenSSL有几个提示:

  1. It is necessary to build OpenSSL libraries using NDK tools, otherwise they will be incompatible with the NDK. 有必要使用NDK工具构建OpenSSL库,否则它们将与NDK不兼容。 Compiling the latest OpenSSL for Android 编译最新的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. 假设这些命令在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. 为了将这些库(ssl和crypto)与NDK中自己的库一起使用,您需要在jni文件夹中创建其他* .mk文件。 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: 并将它们包含在主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 . 图书馆将被放入libs/armabi.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. 如果您将遇到could not load library ... needed by ...错误然后它可能意味着您的库具有版本号的soname。 AFAIK NDK is unable to work with such libraries at this moment. AFAIK NDK目前无法使用此类库。 There is a workaround ( Dalvik is looking for .so file with '.0' extension - why? ): 有一种解决方法( Dalvik正在寻找带有'.0'扩展名的.so文件 - 为什么? ):

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

    where rpl is a linux string replacement tool. 其中rpl是一个linux字符串替换工具。 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. 如果使用C ++编译器,可能会在C函数中出现“未定义的引用”错误。 Use extern "C" {} to avoid this (see "C++ name mangling" for more info). 使用extern "C" {}来避免这种情况(有关详细信息,请参阅“C ++名称修改”)。

  4. At last make sure that there is a network permission in the manifest. 最后确保清单中有网络权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM