使用我的Android本机代码与openssl libs(ssl / crypto)链接时出现以下错误。我使用openssl v1.0.2l代码并使用android-sdk / ndk-bundle目录下的ndk-build构建它。
错误信息
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pkg-name.client, PID: 26925
java.lang.UnsatisfiedLinkError: **dlopen failed: cannot locate symbol "i2d_DHxparams"** referenced by "/data/app/com.pkg-name.client-1/lib/arm/libnative-lib.so"...
我的android-config.make文件包含以下内容:
#
# These flags represent the build-time configuration of openssl for android
#
# They were pruned from the "Makefile" generated by running ./Configure from import_openssl.sh
#
# From CLFAG=
LOCAL_CFLAGS += -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -O3 -fomit-frame-pointer -Wall #-DTERMIO
# From DEPFLAG=
LOCAL_CFLAGS += -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_SCTP \
-DOPENSSL_NO_CAMELLIA -DOPENSSL_NO_CAPIENG -DOPENSSL_NO_CAST -DOPENSSL_NO_CMS -DOPENSSL_NO_GMP -DOPENSSL_NO_IDEA -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_MDC2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_SHA0 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SEED -DOPENSSL_NO_STORE -DOPENSSL_NO_WHIRLPOOL
#Copied by seaching for the OPENSSL_NO_
#LOCAL_CFLAGS += -DOPENSSL_NO_DEPRECATED
# Extra
LOCAL_CFLAGS += -DOPENSSL_NO_HW -DOPENSSL_NO_ENGINE -DZLIB
# Debug
# LOCAL_CFLAGS += -DCIPHER_DEBUG
如果我需要启用任何标记,请告诉我。 我尝试了Android的预构建openssl库并遇到了类似的问题。
答案 0 :(得分:0)
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.pkg-name.client, PID: 26925 java.lang.UnsatisfiedLinkError: **dlopen failed: cannot locate symbol "i2d_DHxparams"** referenced by "/data/app/com.pkg-name.client-1/lib/arm/libnative-lib.so"...
i2d_DHxparams
是OpenSSL 1.1.0中的一个宏,而不是1.0.2:
$ cd openssl
$ grep -IR i2d_DHxparams
crypto.map: i2d_DHxparams;
util/libcrypto.num:i2d_DHxparams 2206 1_1_0 EXIST::FUNCTION:DH
doc/man3/d2i_X509.pod:i2d_DHxparams,
include/openssl/dh.h:# define i2d_DHxparams_fp(fp,x) \
include/openssl/dh.h: ASN1_i2d_fp(i2d_DHxparams,(fp), (unsigned char *)(x))
include/openssl/dh.h:# define i2d_DHxparams_bio(bp,x) \
include/openssl/dh.h: ASN1_i2d_bio_of_const(DH, i2d_DHxparams, bp, x)
include/openssl/dh.h:int i2d_DHxparams(const DH *a, unsigned char **pp);
crypto/dh/dh_ameth.c: return i2d_DHxparams(a, pp);
crypto/dh/dh_asn1.c:int i2d_DHxparams(const DH *dh, unsigned char **pp)
apps/dhparam.c: i = i2d_DHxparams_bio(out, dh);
听起来你可能正在使用错误的标题或库。也许您在路径上有1.1.0标头,并且它们在Android标头之前被拾取。
编辑 :看起来OpenSSL 1.0.2中也存在符号:
$ git checkout OpenSSL_1_0_2-stable
$ grep -IR i2d_DHxparams
crypto.map: i2d_DHxparams;
util/libeay.num:i2d_DHxparams 4683 EXIST::FUNCTION:DH
crypto/dh/dh.h:# define i2d_DHxparams_fp(fp,x) \
crypto/dh/dh.h: ASN1_i2d_fp(i2d_DHxparams,(fp), (unsigned char *)(x))
crypto/dh/dh.h:# define i2d_DHxparams_bio(bp,x) \
crypto/dh/dh.h: ASN1_i2d_bio_of_const(DH, i2d_DHxparams, bp, x)
crypto/dh/dh.h:int i2d_DHxparams(const DH *a, unsigned char **pp);
crypto/dh/dh_ameth.c: return i2d_DHxparams(a, pp);
crypto/dh/dh_asn1.c:int i2d_DHxparams(const DH *dh, unsigned char **pp)
apps/dhparam.c: i = i2d_DHxparams_bio(out, dh);
但它似乎没有出现在1.0.1中:
$ grep -IR i2d_DHxparams
crypto.map: i2d_DHxparams;