"Could NOT find OpenSSL" when building for Android
NexZhu opened this issue · 5 comments
Hi, I'm using NDK's cmake to build rsocket-cpp for Android
First I got:
Could NOT find Folly (missing: FOLLY_LIBRARY FOLLY_BENCHMARK_LIBRARY
FOLLY_INCLUDE_DIR)
So I added the following to CMakeLists.txt:
set(FOLLY_LIBRARY "/usr/local/opt/folly/lib" )
set(FOLLY_BENCHMARK_LIBRARY "/usr/local/opt/folly/lib/libfollybenchmark.a" )
set(FOLLY_INCLUDE_DIR "/usr/local/include/folly" )
Then I got:
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES
OPENSSL_INCLUDE_DIR)
So I added the following to CMakeLists.txt:
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl" )
set(OPENSSL_LIBRARIES "/usr/local/opt/openssl/lib" )
set(OPENSSL_INCLUDE_DIR "/usr/local/opt/openssl/include" )
Then I got:
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES) (found
version "1.0.2l")
I've also tried building OpenSSL for Android following this instruction:
Then changed above lines to:
set(OPENSSL_ROOT_DIR "/usr/local/ssl/android-26" )
set(OPENSSL_LIBRARIES "/usr/local/ssl/android-26/lib" )
set(OPENSSL_INCLUDE_DIR "/usr/local/ssl/android-26/include" )
The result was pretty much the same:
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES) (found
version "1.1.0f")
It's finding the headers, but not the libraries.
@lexs How do you guys at Facebook build rsocket-cpp for Android?
Also, is it possible to share the JNI code (or whatever you use to make it available in Java)?
Thank you!
Hey, really sorry about not responding sooner here. Was out on holiday and then forgot to check github notifications.
Anyway, looking through our code I don't think openssl should be a dependency, I'll try removing it. Can you try commenting it out and see how it goes?
For the JNI part, we have a very bare wrapper which is basically Subscription subscribe(String data, String metadata, int initialRequestN, Callback callback);
and
interface Subscription {
void cancel();
void request(int n);
}
interface Callback {
void onResponse(String data, String metadata);
void onError(String error);
}
All the connection logic etc is fully handled in C++.
Seems like OpenSSL is used by folly::AsyncSocket which we use for TCP, so it's indeed needed. @NexZhu What OS are you running on? Under OSX this works for me cmake -DCMAKE_BUILD_TYPE=DEBUG -DOPENSSL_ROOT_DIR=/usr/local/ssl -DOPENSSL_LIBRARIES=/usr/local/ssl/lib ../
but it also works without the OPENSSL options.
We build both rsocket and folly with Buck, so it's quite a different setup.
@lexs On OSX, using system's cmake like you suggested works fine, but this way it's not built for Android right? Using the cmake bundled in NDK from Android Studio won't work. The difference is it has some extra arguments:
/Users/nex/Library/Android/sdk/cmake/3.6.4111459/bin/cmake \
-DCMAKE_BUILD_TYPE=DEBUG \
-H/Users/nex/workspaces/os/rsocket-cpp \
-B/Users/nex/workspaces/os/rsocket-android-demo/app/.externalNativeBuild/cmake/debug/armeabi \
-G"Android Gradle - Ninja" \
-DANDROID_ABI=armeabi \
-DANDROID_NDK=/Users/nex/Library/Android/sdk/ndk-bundle \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/nex/workspaces/os/rsocket-android-demo/app/build/intermediates/cmake/debug/obj/armeabi \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_MAKE_PROGRAM=/Users/nex/Library/Android/sdk/cmake/3.6.4111459/bin/ninja \
-DCMAKE_TOOLCHAIN_FILE=/Users/nex/Library/Android/sdk/ndk-bundle/build/cmake/android.toolchain.cmake \
-DANDROID_PLATFORM=android-21
When I build the RSocket, for CMake to be able to find the OpenSSL, I do either of these two:
- Give the path of OpenSSL to CMake with a flag
brew link --force openssl
Call this command once, if you use MacOs with Brew.
Did this help?
brew link --force openssl
Please reopen if otherwise.