Compiling a Cocos2d-x project with OpenSSL for Android

I’m trying to compile my Cocos2d-x project with OpenSSL for Android. I can run the project properly on Visual Studio Community 2013, but can’t compile it on the command line with cocos compile -p android --android-studio.

I installed OpenSSL to path project\cocos2d\external\OpenSSL-Win32 and added the OpenSSL include path to the Android.mk file:

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../proj.win32 \
     		    $(LOCAL_PATH)/../../../cocos2d/external/OpenSSL-Win32/include

I think I should also add some library references, but I don’t know how.

Currently, I get these errors when I try to compile it to Android:

jni/…/…/…/proj.win32/EncryptionHelper.cpp:61: error: undefined reference to ‘EVP_CIPHER_CTX_new’
jni/…/…/…/proj.win32/EncryptionHelper.cpp:65: error: undefined reference to ‘EVP_aes_256_cbc’
jni/…/…/…/proj.win32/EncryptionHelper.cpp:65: error: undefined reference to ‘EVP_EncryptInit_ex’
jni/…/…/…/proj.win32/EncryptionHelper.cpp:67: error: undefined reference to ‘EVP_EncryptUpdate’
jni/…/…/…/proj.win32/EncryptionHelper.cpp:70: error: undefined reference to ‘EVP_EncryptFinal_ex’
jni/…/…/…/proj.win32/EncryptionHelper.cpp:73: error: undefined reference to ‘EVP_CIPHER_CTX_free’

OpenSSL depends son libcrypto. I don’t know why not use prebuilt library provided by cocos2d-x.

You mean the one here: cocos2d\external\curl\prebuilt\android?

I only just realized that libcrypto.a comes with Cocos2d-x. I had already downloaded the static library from elsewhere along with OpenSSL header files because they weren’t included in Cocos.

I actually managed to solve this. I’ll post the solution later.

I downloaded libcrypto.a along with the header files from here: https://github.com/r4sas/OpenSSL-1.1-Android-Prebuilt.

Added this to Android.mk:

include $(CLEAR_VARS)
LOCAL_MODULE    := crypto_static
LOCAL_SRC_FILES := libcrypto.a
include $(PREBUILT_STATIC_LIBRARY)
...
LOCAL_STATIC_LIBRARIES := cocos2dx_static \ crypto_static

It compiles properly now.