Created
March 5, 2021 10:54
-
-
Save rhulha/3a2bce7dc3d43c4bab8a14a31feecc38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compiling an Android project that depends on OpenSSL using Prefabs | |
Prefabs are a new feature of the Android Gradle Plugin 4.0. | |
Here is an outdated but still informative blog post about the subject: | |
https://android-developers.googleblog.com/2020/02/native-dependencies-in-android-studio-40.html | |
In the app build.gradle you simply add: | |
dependencies { | |
implementation 'com.android.ndk.thirdparty:openssl:1.1.1g-alpha-1' | |
} | |
Here is a list of available packages: | |
https://maven.google.com/web/index.html?q=com.android.ndk.thirdparty#com.android.ndk.thirdparty:openssl | |
Currently available packages are: curl, jsoncpp and openssl. | |
In the android section in the app build.gradle you also add: | |
buildFeatures { | |
prefab true | |
} | |
And in the defaultConfig section in the android section in the app build.gradle you also add: | |
externalNativeBuild { | |
cmake { | |
arguments "-DANDROID_STL=c++_shared" | |
} | |
} | |
Otherwise you get this error message: | |
> User is using a static STL but library requires a shared STL | |
In the CMakeList.txt you add: | |
find_package(openssl REQUIRED CONFIG) | |
And to target_link_libraries you add: | |
openssl::crypto | |
openssl::ssl | |
I'm trying to include
#include <openssl/sha.h>
and I added the OpenSSL library as you mentioned, unfortunately my app is crashing:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libcrypto.so" not found: needed by /data/app/~~2-M8lYDV9CwRUTUVJ-xI7Q==/com.MYAPPNKq4Bj7P2ot9_6vUGCPvhQ==/lib/x86/libMYLIB.so in namespace classloader-namespace
do you know why that is happening and what I'm doing wrong? alternatively, is there a way to link the lib statically, so libcrypto.a
instead of libcrypto.so
? Looks like someone on stackoverflow says that the library is compiled incorrectly, but that's not using a prefab...
Take a look at this example: that one might be more up to date: https://github.com/android/ndk-samples/tree/master/prefab/curl-ssl
@mrousavy did you ever figure this out? I encountered the same issue
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! 👏