How to Include custom libcrypto in my apk instead of the prebuilt Android's.

362 views
Skip to first unread message

Tanya Shrivastava

unread,
Jan 2, 2024, 12:10:41 PMJan 2
to android-ndk
I have an apk which is using a jniLib named "libpriv.so". This libpriv.so is internally utilizing a specific version of libcrypto and libssl. I want my application to be platform independent and use my specific libcrypto and libssl instead of the prebuilt Android one. I am using Android.mk. How to do it?

Andrea Fiorito

unread,
Jan 16, 2024, 11:14:47 AMJan 16
to android-ndk
Not sure if it's helpful to you, I did that a couple of weeks ago for a library, but I'm using Cmake (which is now the preferred way for building C++ on android studio). I compiled the library from the source code online.

On my cmake i have this block

    set(CMAKE_SYSROOT_OLD ${CMAKE_SYSROOT})
    set(CMAKE_SYSROOT "")
    find_library(lib_crypto NAMES crypto
            HINTS ${OPENSSL_LIB_DIR}/${CMAKE_ANDROID_ARCH_ABI})
    set(CMAKE_SYSROOT ${CMAKE_SYSROOT_OLD})

I had to wrap the find_library with those calls as a workaround to be able to find the library with the path specified.

then on the block target_link_libraries

target_link_libraries(${PROJECT_NAME} 
${lib_crypto}
)

on my build.gradle file i specify where is the path that contains the folders with the .so for the different architectures

android {
    defaultConfig {
        externalNativeBuild {
            cmake {
                cppFlags '-std=c++17'
                arguments "-DOPENSSL_LIB_DIR="+"/Users/bloom/sw_develop/Libraries/openssl/build"
                arguments "-DOPENSSL_LIB_DIR="+"/Users/bloom/sw_develop/Libraries/openssl/build"
            }
        } 
    }
}

Of course I set up also the path for the include files with this line:

    include_directories( ${OPENSSL_INCLUDE_DIR} )

Hope it helps or at least points you on the right direction.

Dan Albert

unread,
Jan 16, 2024, 6:23:42 PMJan 16
to andro...@googlegroups.com
https://github.com/android/ndk-samples/tree/main/prefab/curl-ssl shows how to use openssl from an AAR. The sample is using something that's sorely out of date, so you'd probably want to clone https://android.googlesource.com/platform/tools/ndkports/, update it to the version you want, then publish that somewhere rather than using the old one that's currently in our maven repo.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/1aaf98e7-534c-4c6b-a951-cea531644434n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages