Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rhulha/3a2bce7dc3d43c4bab8a14a31feecc38 to your computer and use it in GitHub Desktop.
Save rhulha/3a2bce7dc3d43c4bab8a14a31feecc38 to your computer and use it in GitHub Desktop.
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
@rhulha
Copy link
Author

rhulha commented Nov 3, 2021

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

@GNUGradyn
Copy link

@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