Android NDK OpenSSL错误交叉编译

我是NDK的新手,我正在按照本指南为Android构建OpenSSL,我正在使用Windows 7和Cygwin。

我在尝试构建OpenSSL库时遇到了错误。

# From the 'root' directory $ . ./setenv-android.sh $ cd openssl-1.0.1g/ $ perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org $ ./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=/usr/local/ssl/$ANDROID_API $ make depend $ make all 

当我尝试make depend命令时,我有2个错误:

cryptlib.c:171:3: error: #error "Inconsistency between crypto.h and cryptlib.c" # error "Inconsistency between crypto.h and cryptlib.c"

cryplib.c第171行说:

 #if CRYPTO_NUM_LOCKS != 41 # error "Inconsistency between crypto.h and cryptlib.c" #endif 

我不知道如何解决这个错误。

另一个是uid.c:77:10: error: #include expects "FILENAME" or #include OPENSSL_UNISTD

如果我将uid.c中的第77行更改为#include 我在Makefile中收到错误,所以我不知道是否是修复它的方法,错误是在依赖Makefile中。

 depend: @[ -z "$(THIS)" -o -f buildinf.h ] || touch buildinf.h # fake buildinf.h if it does not exist @[ -z "$(THIS)" ] || $(MAKEDEPEND) -- $(CFLAG) $(INCLUDE) $(DEPFLAG) -- $(PROGS) $(LIBSRC) @[ -z "$(THIS)" -o -s buildinf.h ] || rm buildinf.h @[ -z "$(THIS)" ] || (set -e; target=depend; $(RECURSIVE_MAKE) ) @if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi 

另一个问题是,我是否可以使用本指南将OpenSSL库构建到64位arch。 (x86_64,arm64和mips64)我没有在这些体系结构中找到有关Android的OpenSSL的信息,所有关于它的post都很旧,而且那些针对Android不存在

编辑

我找到了一种方法来解决我的问题(不是最好的但是它有效),问题是由于某些路径中的一些错误,因为我试图在Windows上使用Cywin而某些文件(我没有哪些)是试图找到一些不存在的路径,因为我在Windows而不是Linux,所以我只是在虚拟机上安装Ubuntu并再次尝试本指南 ,我可以编译库,我有libcrypto.a libcrypto.so libssl .a libssl.so适用于Android ARM,x86,mips,ARM64和x86_64架构。

但是这些库不适用于x86_64和ARM64,当我尝试使用android.mk为x86_64或arm64 eabi编译.c时由于某些兼容性错误而无法编译,但是如果尝试编译相同的.c文件有“x86_64”或“arm-64”用于x86或arm eabi它编译,因此它们仍然是32位库,这不是答案,因为我需要所有架构的库(至少对于armv5, armv7,armv8-64,x86,x86_64),这只是一小步。

我将更新以帮助有同样问题的人,如果有人想帮助我。

当我尝试make depend命令时,我有2个错误:

 cryptlib.c:171:3: error: #error "Inconsistency between crypto.h and cryptlib.c" # error "Inconsistency between crypto.h and cryptlib.c" 

符号链接存在问题。 用tar zxvf再次解压缩tar包。 然后,validation头文件不是 0长度。

另请参阅OpenSSL邮件列表中crypto.h和cryptlib.c之间的不一致 。 以及如何将符号链接文件从Linux复制到Windows然后再返回到Linux,但仍将其保留为 Stack Overflow上的符号链接 。

使用本指南并修改文件setenv-android.sh您可以轻松编译arm,x86和mips的openssl。

您只需修改_ANDROID_NDK _ANDROID_ARCH _ANDROID_EABI _ANDROID_API参数

注意 :对于mips,你必须在文件中添加一些行

120行左右:

  arch-mips) ANDROID_TOOLS="mipsel-linux-android-gcc mipsel-linux-android-ranlib mipsel-linux-android-ld" ;; 

200行左右:

 if [ "$_ANDROID_ARCH" == "arch-mips" ]; then export MACHINE=mipsel export RELEASE=2.6.37 export SYSTEM=android export ARCH=mips export CROSS_COMPILE="mipsel-linux-android-" fi 

如果您按照指南操作,您将拥有libcrypto.a,libssl.a,libcrypto.so和libssl.so。

如果你想要64位架构的库你可以使用adb从一个设备拉,所有android设备在64位版本的/system/lib64有libcrypto.so和libssl.so(仅在64位设备中)和/system/lib 32bits版本,你可以使用一个模拟器,如果你可以在这个链接中想要64位版本的静态库(libcrypto.a和libssl.a),你可以找到它的方法。