sony/easyhttpcpp

Build easyhttpcpp for Android NDK

Closed this issue · 7 comments

Is there any way (existing documentation or script ?) to easily compile this project for Android platform? Is cross-compiling all dependencies one by one (Poco, openssl etc...) and then at the end easyhttpcpp itself manually the only option?

Hi @MGasztold

Thank you for your interest in easyhttpcpp (EasyHttp).

I haven't tried cross compiling EasyHttp on Android platform yet but it should be possible.
Yes, you will have to cross compile OpenSSL and Poco first and then use them to cross compile EasyHttp.

Some references I found online:

I am planning to write a cmake toolchain file to simplify the cross build but in the meantime you can start with the links above. I will try them myself as well.

Let me know if that helps.

Hi @MGasztold

I was able to cross-build EasyHttp for Android from a Ubuntu 16.04 host. Here are my steps.

Setup Android NDK.

  • Download NDK. I used android-ndk-r15c for my test.
  • Create the toolchain with make-standalone-toolchain.sh script.
cd android-ndk-r15c
build/tools/make-standalone-toolchain.sh --platform=android-21 --toolchain=arm-linux-androideabi-4.9 --install-dir=../android-toolchain-arm

Build OpenSSL

  • Download. I used openssl-1.1.0h for my test.
  • Install OpenSSL. I used instructions from here and here.

Next to build Poco and EasyHttp, we will need Android cmake toolchain file. Here's mine:

set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_ANDROID_STANDALONE_TOOLCHAIN /path/to/android/standalone/toolchain/root)

set(OPENSSL_ROOT_DIR "/path/where/openssl/was/installed")
set(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include")

set(CMAKE_INCLUDE_PATH ${OPENSSL_INCLUDE_DIR})
set(CMAKE_LIBRARY_PATH "${OPENSSL_ROOT_DIR}/lib")

include_directories(
        "${OPENSSL_INCLUDE_DIR}"
)
link_directories(
        "${OPENSSL_ROOT_DIR}/lib"
)

Save this to a file AndroidToolchain.cmake. (Make sure you change the paths first)

Build Poco

  • Download. I used poco-1.9.0-release for my test.
cd poco-poco-1.9.0-release
mkdir _build
cd _build
cmake \
  -DCMAKE_BUILD_TYPE=Release \
  -DPOCO_ANDROID=ON \
  -DPOCO_UNBUNDLED=OFF -DENABLE_ENCODINGS=OFF -DENABLE_REDIS=OFF -DENABLE_XML=ON -DENABLE_JSON=ON -DENABLE_UTIL=ON -DENABLE_NET=ON -DENABLE_NETSSL=ON -DENABLE_CRYPTO=ON -DENABLE_DATA=ON -DENABLE_DATA_SQLITE=ON -DENABLE_ZIP=OFF -DENABLE_DATA_MYSQL=OFF -DENABLE_DATA_ODBC=OFF -DENABLE_MONGODB=OFF -DENABLE_PDF=OFF -DENABLE_SEVENZIP=OFF -DENABLE_PAGECOMPILER=OFF -DENABLE_PAGECOMPILER_FILE2PAGE=OFF -DENABLE_TESTS=OFF \
  -DCMAKE_TOOLCHAIN_FILE=/path/to/AndroidToolchain.cmake \
  -DCMAKE_INSTALL_PREFIX=../_install ..

make install

Poco is installed inside poco-poco-1.9.0-release/_install.

Build EasyHttp

  • Download. I used easyhttpcpp 1.0.0 release for this test.
cd easyhttpcpp-1.0.0
mkdir _build
cd _build
cmake \
  -DPoco_DIR=/path/to/poco-poco-1.9.0-release/_install/lib/cmake/Poco \
  -DCMAKE_TOOLCHAIN_FILE=/path/to/AndroidToolchain.cmake \
  -DCMAKE_INSTALL_PREFIX=../_install ..

make install

EasyHttp is installed inside easyhttpcpp-1.0.0/_install.

Build sample

cd easyhttpcpp-1.0.0/samples/SimpleHttpClient
mkdir _build
cd _build
cmake \
  -DPoco_DIR=/path/to/poco-poco-1.9.0-release/_install/lib/cmake/Poco \
  -Deasyhttpcpp_DIR=/path/to/easyhttpcpp-1.0.0/_install/lib/cmake/easyhttpcpp \
  -DCMAKE_TOOLCHAIN_FILE=/path/to/AndroidToolchain.cmake ..

make

Let me know it helps.

@shekharhimanshu Thanks a lot for this. I am going to try it asap and let you know if it works smoothly on OS X as this is a system i work on.

Hi @MGasztold,

Were you able to build EasyHttp on your side? Let me know if you are having troubles at any step.

@MGasztold

I am closing this issue due to inactivity. Please feel free to open a new one.

Hi Himanhu,
I'm unable to build the poco, its giving an error when i ran
"cmake -DCMAKE_BUILD_TYPE=Release -DPOCO_ANDROID=ON -DPOCO_UNBUNDLED=OFF -DENABLE_ENCODINGS=OFF -DENABLE_REDIS=OFF -DENABLE_XML=ON -DENABLE_JSON=ON -DENABLE_UTIL=ON -DENABLE_NET=ON -DENABLE_NETSSL=ON -DENABLE_CRYPTO=ON -DENABLE_DATA=ON -DENABLE_DATA_SQLITE=ON -DENABLE_ZIP=OFF -DENABLE_DATA_MYSQL=OFF -DENABLE_DATA_ODBC=OFF -DENABLE_MONGODB=OFF -DENABLE_PDF=OFF -DENABLE_SEVENZIP=OFF -DENABLE_PAGECOMPILER=OFF -DENABLE_PAGECOMPILER_FILE2PAGE=OFF -DENABLE_TESTS=OFF -DCMAKE_TOOLCHAIN_FILE=/home/animesh/Desktop/pocoandroid -DCMAKE_INSTALL_PREFIX=../_install" inside _build and the error was
""CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.

CMake Error: The source directory "/home/animesh/Desktop/pocoandroid/poco-master/_build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

Then I created a cmakelists.txt inside build but there was still there.

Can you please help me with if I'm missing something or if you can provide the exact steps to build poco for android.

Hi @AnchoretBaladev

Thank you for your interest in EasyHttp.
Since your problem is different than this issue, could you please open a new issue?

I will be happy to help you there.
Thanks