Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

Updated Wiki: Setup and Build on Android 2.2

$
0
0

How to build and setup for Android on Linux (2.2)

First, follow all the instructions on Setup and Build on Linux. While some steps could be skipped if you only want to build for Android, it is useful to diagnose problems with a desktop build first.

Second, while our dependencies require a Linux system to build, once they are built you can transfer the products to a Windows computer and use them with your existing Android project under Eclipse. More information on this is provided in the relevant step.

Casablanca depends on Boost, libiconv, and OpenSSL when used on Android. It is a non-trivial task to cross-compile libraries for Android, however there are scripts available online with nonrestrictive licenses to compile many popular libraries.

This document will walk through the steps to build Casablanca and its dependencies into a form suitable for use with Android applications.

For this walkthrough, we assume you are working within the Build_Android directory of the casablanca project.
git clone https://git01.codeplex.com/casablanca
pushd casablanca/Build_android

Install the Android SDK

The following instructions are written and tested against the android SDK version r23. Future and past versions may or may not work. The android SDK is available at http://developer.android.com/sdk/index.html. The sdk standalone download can be found under the tag "Get the SDK for an existing IDE".

For this tutorial, we assume it is installed at ~/android-sdk-linux/.

Note: you may need to launch the SDK Manager (with ~/android-sdk-linux/tools/android sdk) and download the "Android 4.4.2 (API 19)" package category.

Install the Android NDK

The following instructions are written and tested against the android NDK version r9d. Future and past versions may or may not work. The android NDK is available at http://developer.android.com/tools/sdk/ndk/index.html. If version r9d is not available for download, hard links are provided below.

For this tutorial, we assume it is installed at ~/android-ndk-r9d/.

Building OpenSSL

To build OpenSSL, use the included android_configure_armeabiv7.sh script. This is based on the openssl1.0.1g-android project.
bash
mkdir openssl
pushd openssl
wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
tar xzf openssl-1.0.1h.tar.gz
cd openssl-1.0.1h
export ANDROID_NDK="$HOME/android-ndk-r9d/"
. ../../android_configure_armeabiv7.sh
./Configure android no-shared --prefix="`pwd`/../r9d-9-armeabiv7" --openssldir=openssl
make all install_sw
exit

This completes building OpenSSL.

Original project link: https://github.com/aluvalasuman/openssl1.0.1g-android

Building libiconv

To build libiconv, we use a process based on a blog post by Danilo Guilianelli.

bash
cd libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar xzf libiconv-1.13.1.tar.gz
patch -b -p0 < libiconv.patch
cd libiconv-1.13.1
./configure
cd ../jni
~/android-ndk-r9d/ndk-build
cd ..
mkdir -p r9d-9-armeabiv7a/include
mkdir -p r9d-9-armeabiv7a/lib
cp libiconv-1.13.1/include/iconv.h r9d-9-armeabiv7a/include
cp libs/armeabi-v7a/libiconv.so r9d-9-armeabiv7a/lib
exit


Original blog post: http://danilogiulianelli.blogspot.com/2012/12/how-to-cross-compile-libiconv-for.html

Building Boost

To build Boost, use a slight modification of the script provided by MysticTreeGames.

git clone https://github.com/MysticTreeGames/Boost-for-Android
pushd Boost-for-Android
git checkout 8075d96cc9ef42d5c52d233b8ee42cb8421a2818
patch -p1 < ../boost-for-android.patch
./build-android.sh "$HOME/android-ndk-r9d/"
popd


This completes building Boost.

project link: https://github.com/MysticTreeGames/Boost-for-Android

Preparing the Casablanca build

Casablanca uses CMake for cross-platform compatibility. To build on Android, we specifically use the android-cmake project by Andrey Kamaev.

git clone https://github.com/taka-no-me/android-cmake.git


This completes the preparation for building Casablanca.

project link: https://github.com/taka-no-me/android-cmake/

Building Casablanca

Now we are ready to build Casablanca for Android.
mkdir build.armv7.debug
pushd build.armv7.debug
export ANDROID_NDK="$HOME/android-ndk-r9d/"
cmake ../../Release \
	-DCMAKE_TOOLCHAIN_FILE=../android-cmake/android.toolchain.cmake \
	-DANDROID_ABI=armeabi-v7a \
	-DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.8 \
	-DANDROID_STL=none \
	-DANDROID_STL_FORCE_FEATURES=ON \
	-DANDROID_NATIVE_API_LEVEL=android-9 \
	-DANDROID_GOLD_LINKER=OFF \
	-DCMAKE_BUILD_TYPE=Debug \
	-DANDROID_NDK="${ANDROID_NDK}"
make -j 3
popd

This will produce a shared library called "libcpprest.so" inside the 'build.armv7.debug/Binaries' directory for the armeabiv7a architecture. To build a release version, set the CMAKE_BUILD_TYPE to Release instead of Debug.

Using Casablanca

At a minimum, you will need to link against the following from your project:
  • build.armv7.debug/Binaries/libcpprest.so
  • libiconv/r9d-9-armeabiv7a/lib/libiconv.so

You will also need to add the following paths as additional include directories:
  • ../Release/include
  • Boost-for-Android/build/include/boost-1_55

Use the included documentation with your NDK to add these prebuilt libraries and include paths. An outdated version of the relevant documentation is hosted at http://www.kandroid.org/ndk/docs/PREBUILTS.html.

If you wish to use this on a Windows installation of Eclipse and the Android NDK, you can copy the relevant libraries and include files over and they will work perfectly.

Final Notes

The above instructions are useful for reference, however if you encounter trouble while building or need to build Casablanca on multiple computers we have included a script which automatically performs the above steps.

To use it, issue the following commands:
~/casablanca/Build_android$ mkdir build && cd build
~/casablanca/Build_android/build$ ANDROID_NDK=~/android-ndk-r9d ../configure.sh

This will automatically build a Release and Debug version of Casablanca under the build.armv7.debug and build.armv7.release folders.

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>