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

发布于 2024-09-06 09:47:20 字数 249 浏览 5 评论 0原文

我正在尝试使用 Android NDK 将 openssl 库嵌入到我的 Android 应用程序中,但我不知道如何准确使用该库,所以请任何人都可以告诉我如何使用它,请发送源代码供我参考... ....

相关:

如何在 Android/Linux 上构建 OpenSSL ?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗弃M 2024-09-13 09:47:20

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

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

深空失忆 2024-09-13 09:47:20

关于在 Android 上使用 OpenSSL 有几个技巧:

  1. 必须使用 NDK 工具构建 OpenSSL 库,否则它们将与 NDK 不兼容。 编译适用于 Android 的最新 OpenSSL

     CC=~/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc
     ./配置android-armv7
     导出 ANDROID_DEV=~/android-ndk-r9//platforms/android-8/arch-arm/usr
     制作构建库
    

    假设这些命令是在OpenSSL的源码目录中执行的。

  2. 为了将这些库(ssl 和 crypto)与您自己的 NDK 库一起使用,您需要在 jni 文件夹中创建其他 *.mk 文件。例如:

    <前><代码>包括$(CLEAR_VARS)

    LOCAL_MODULE := ssl-加密
    LOCAL_SRC_FILES := openssl-crypto/libcrypto.so

    包括 $(PREBUILT_SHARED_LIBRARY)

    并将它们包含到主 Android.mk 中:

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

    并且可能添加

    <前><代码>包括$(CLEAR_VARS)

    在其后面以避免错误。库将被放置在 libs/armabi.apk 中。

  3. 如果您遇到无法加载库...需要...错误,那么您的库可能有带有版本号的soname。 AFAIK NDK 目前无法使用此类库。有一个解决方法(Dalvik 正在寻找 .so 文件带有“.0”扩展名 - 为什么?):

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

    其中rpl是一个Linux字符串替换工具。在构建之后、运行应用程序之前运行此脚本,它将从项目文件中删除版本号。

    如果您使用 C++ 编译器,您的 C 函数中可能会出现“未定义引用”错误。使用 extern "C" {} 可以避免这种情况(有关详细信息,请参阅“C++ 名称修改”)。

  4. 确保清单中有网络权限。

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 stumble opon could not load library ... needed by ... error then your library may have 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 the building and before the running of your application and it will remove the version number from the project files.

    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. Make sure that there is a network permission in the manifest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文