在android中使用openssl库

本文解决了在Windows环境下使用Cygwin编译OpenSSL库到Android NDK时遇到的问题,通过更换开源项目实现了成功编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://stackoverflow.com/questions/9065409/unable-to-build-external-openssl-library-for-android-ndk-on-windows-cygwin


1 down vote favorite
1
share [g+] share [fb]

Please login or register to vote for this post.

(click on this box to dismiss)

I need to build the latest OpenSSL (1.0.0g) for an Android application. I am trying to follow the example given by https://github.com/fries/android-external-openssl, but I just can't get it built.

I am running Windows 7 Professional (64-bit) with a complete and recent Cygwin. I have installed the Android SDK and NDK, and I can successfully build and run the NDK's hello-jni sample application.

I created a new sample NDK app called hello-openssl. In its jni directory, I created an openssl directory. There, I unzipped https://github.com/fries/android-external-openssl/zipball/master, which gave me this tree structure under c:\android\android-ndk\samples\hello-openssl:

jni
+- openssl
   +- apps
   +- crypto
   +- include
      +- openssl
   +- ssl

I then modified the Android.mk file in the jni directory in an attempt to include the OpenSSL files:

subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
    openssl \
))

include $(subdirs)

Now when I execute ndk-build, it compiles several .c files, but then quickly fails:

Compile thumb  : crypto <= cryptlib.c
In file included from jni/openssl/crypto/cryptlib.c:117:
jni/openssl/crypto/cryptlib.h:65:18: error: e_os.h: No such file or directory
jni/openssl/crypto/cryptlib.h:72:28: error: openssl/crypto.h: No such file or directory

I found http://osdir.com/ml/android-ndk/2010-07/msg00424.html, which tells me to "addjni and jni/include to the above LOCAL_C_INCLUDES" in crypto/Android.mk, but I can't figure out the syntax I should use to achieve this.

I also can't figure out of I have the correct directory structure.

I sincerely appreciate any help that can be offered.

Thanks!

link | improve this question

38% accept rate
 
feedback

1 Answer

up vote 2 down vote accepted

I solved this problem by abandoning https://github.com/fries/android-external-openssl and instead using https://github.com/guardianproject/openssl-android.

It is based on a more recent OpenSSL (1.0.0a), and it builds in the NDK without any modifications.

Note that in order to use these libraries in an Android app, you must rename them. If you simply include the resulting libssl.so and libcrypto.so in your app, then call System.LoadLibrary ("crypto") and System.LoadLibrary ("ssl"), you will get the OpenSSL libraries included in the Android system, not your custom libraries.

To do this, just do a full-word search and replace ("libssl" -> "libsslx", and "libcrypto" -> "libcryptox") in each Android.mk (i.e, in /crypto, /ssl, and /apps).

Then in your Android app, call SystemLoadLibrary ("cryptox") and System.LoadLibrary ("sslx")

link | improve this answer


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值