Closed zzhangxiaoyun closed 5 years ago
等不及的话可以参考一下这个,这个里面的 shell 脚本我下午亲自尝试过了,完全可以编译出 1.1.1a 来,而且支持最新的 NDK 19c 非常不错,我正在尝试把这个融合到我这个脚本里来
https://stackoverflow.com/questions/52717228/how-to-compile-openssl-1-1-1-for-android
好的,我试试,感谢感谢!
感谢提供OpenSSL 1.1.1a的工具脚本和编译好的静态库。
不管是上面提供的静态库,还是使用更新的脚本自己在mac上编译生成的静态库。在Android项目中使用时,依赖libcrypto.a libss.a编译时,都不能编译成功,反复查找原因折腾两天还是没能解决,求助帮忙啊!
./gradlew assembleDebug编译时错误日志如下:
B000000115448a:lcv-sdk-android zhangxiaoyun01$ ./gradlew assembleDebug
Task :library:common:compileJava 警告: [options] 未与 -source 1.7 一起设置引导类路径 1 个警告
Task :library:http:compileJava 警告: [options] 未与 -source 1.7 一起设置引导类路径 1 个警告
Task :library:lcv-core:compileJava 警告: [options] 未与 -source 1.7 一起设置引导类路径 注: 某些输入文件使用了未经检查或不安全的操作。 注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。 1 个警告
Task :sdk:lcv-android:compileDebugJavaWithJavac 注: /Users/zhangxiaoyun01/StudioProjects/lcv-sdk-android/sdk/lcv-android/src/main/java/com/baidu/xchain/lcv/utils/Utility.java使用或覆盖了已过时的 API。 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 注: 某些输入文件使用了未经检查或不安全的操作。 注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
Task :library:crypto-android:externalNativeBuildDebug FAILED Build crypto-native armeabi-v7a [1/2] Building CXX object CMakeFiles/crypto-native.dir/src/main/cpp/crypto-native.cpp.o clang++: warning: -lz: 'linker' input unused [-Wunused-command-line-argument] In file included from /Users/zhangxiaoyun01/StudioProjects/lcv-sdk-android/library/crypto-android/src/main/cpp/crypto-native.cpp:6: ../../../../src/main/cpp/ecies.c:377:33: warning: self-comparison always evaluates to false [-Wtautological-compare] if (encrypt_data_mac_length != encrypt_data_mac_length ^ 1 warning generated. [2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libcrypto-native.so FAILED: : && /Users/zhangxiaoyun01/program/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi16 --gcc-toolchain=/Users/zhangxiaoyun01/program/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/zhangxiaoyun01/program/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mfpu=vfpv3-d16 -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -std=c++98 -frtti -fexceptions -fPIC -lz -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libcrypto-native.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libcrypto-native.so CMakeFiles/crypto-native.dir/src/main/cpp/crypto-native.cpp.o -L/Users/zhangxiaoyun01/StudioProjects/lcv-sdk-android/library/crypto-android/src/main/cpp/armeabi-v7a ../../../../src/main/cpp/armeabi-v7a/libcrypto.a ../../../../src/main/cpp/armeabi-v7a/libssl.a -llog -latomic -lm && : ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(cryptlib.o):cryptlib.c:function OPENSSL_showfatal: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(eng_openssl.o):eng_openssl.c:function openssl_load_privkey: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(eng_openssl.o):eng_openssl.c:function test_rc4_init_key: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'tcgetattr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'stdin' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function close_console: error: undefined reference to 'stdin' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr' clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
FAILURE: Build failed with an exception.
Build command failed. Error while executing process /Users/zhangxiaoyun01/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/zhangxiaoyun01/StudioProjects/lcv-sdk-android/library/crypto-android/.externalNativeBuild/cmake/debug/armeabi-v7a --target crypto-native} [1/2] Building CXX object CMakeFiles/crypto-native.dir/src/main/cpp/crypto-native.cpp.o clang++: warning: -lz: 'linker' input unused [-Wunused-command-line-argument] In file included from /Users/zhangxiaoyun01/StudioProjects/lcv-sdk-android/library/crypto-android/src/main/cpp/crypto-native.cpp:6: ../../../../src/main/cpp/ecies.c:377:33: warning: self-comparison always evaluates to false [-Wtautological-compare] if (encrypt_data_mac_length != encrypt_data_mac_length ^ 1 warning generated. [2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libcrypto-native.so FAILED: : && /Users/zhangxiaoyun01/program/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi16 --gcc-toolchain=/Users/zhangxiaoyun01/program/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/zhangxiaoyun01/program/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mfpu=vfpv3-d16 -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -std=c++98 -frtti -fexceptions -fPIC -lz -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libcrypto-native.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libcrypto-native.so CMakeFiles/crypto-native.dir/src/main/cpp/crypto-native.cpp.o -L/Users/zhangxiaoyun01/StudioProjects/lcv-sdk-android/library/crypto-android/src/main/cpp/armeabi-v7a ../../../../src/main/cpp/armeabi-v7a/libcrypto.a ../../../../src/main/cpp/armeabi-v7a/libssl.a -llog -latomic -lm && : ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(cryptlib.o):cryptlib.c:function OPENSSL_showfatal: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(eng_openssl.o):eng_openssl.c:function openssl_load_privkey: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(eng_openssl.o):eng_openssl.c:function test_rc4_init_key: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'tcgetattr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'stdin' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function close_console: error: undefined reference to 'stdin' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr' clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
../../../../src/main/cpp/armeabi-v7a/libcrypto.a(cryptlib.o):cryptlib.c:function OPENSSL_showfatal: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(eng_openssl.o):eng_openssl.c:function openssl_load_privkey: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(eng_openssl.o):eng_openssl.c:function test_rc4_init_key: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'tcgetattr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'stdin' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function close_console: error: undefined reference to 'stdin' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr' clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
主要问题在这里: ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(cryptlib.o):cryptlib.c:function OPENSSL_showfatal: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(eng_openssl.o):eng_openssl.c:function openssl_load_privkey: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(eng_openssl.o):eng_openssl.c:function test_rc4_init_key: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'tcgetattr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'stdin' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'stderr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function close_console: error: undefined reference to 'stdin' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr' ../../../../src/main/cpp/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr' clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
把build-openssl_111_4android.sh脚本里的API_LEVEL=23改为 API_LEVEL=16,问题解决了。
最近要用国密ecc,openssl1.1.1a版本中增加了对sm2的支持,尝试在这个脚本基础上编译openssl1.1.1a失败,能帮忙升级一下吗