Skip to content

Commit

Permalink
Merge pull request #63 from MysticTreeGames/devel
Browse files Browse the repository at this point in the history
Merge: Devel into Master
  • Loading branch information
moritz-wundke committed May 12, 2014
2 parents 03a895e + 7ee837b commit 8075d96
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 19 deletions.
20 changes: 12 additions & 8 deletions README.md
Expand Up @@ -26,33 +26,37 @@ To compile Boost for Android you may use one of the following NDKs:

## Usage

### Compiling

$ ./build-android.sh $(NDK_ROOT)

This command will download and build boost against the NDK specified and output the final headers and libs and in the build folder.
This command will download and build boost against the NDK specified and output the final headers and libs in the `build` folder. Make sure to provide an absolute path the the NDK folder!

For more info about usage and available commands use `--help`.

For more info about usage and available commands use --help
### Including

Now that you got boost compiled you must add it to your Android.mk file. First copy the inlcude and lib filder over to your jni folder. I copied it just into: /jni/boost/.
Now that you got Boost compiled you must add it to your `Android.mk` file. Locate the `build` folder and copy the `include` and `lib` folders over to your project's `jni` folder. A recommended path inside your project is `/jni/boost/`.

Add the following to your Android.mk (example for boost 1.48):
Add the following to your `Android.mk` (note that here we're using Boost 1.48 and have assumed that Boost resides inside `/jni/boost`):

LOCAL_CFLAGS += -I$(LOCAL_PATH)/boost/include/boost-1_48
LOCAL_LDLIBS += -L$(LOCAL_PATH)/boost/lib/ -lboost_system -lboost_...

LOCAL_CPPFLAGS += -fexceptions
LOCAL_CPPFLAGS += -frtti

Now use ndk-build and have fun with it!
Also note that you should build your project and Boost with one version of NDK -
STL inside NDK r4 and NDK r5 are not compatible in some subtle details.
Now use `ndk-build` to build and have fun with it!

Note that you should build your project and Boost with the same version of NDK as the C++ STL inside NDK r4 and NDK r5 are not compatible in some subtle details.


## Troubleshooting

In case you encounter bunch of linker errors when building your app with boost,
this might help:

### Building from a 64 bit machine (linux)
### Building from a 64 bit machine (Linux)

Make sure you have installed the 32 bit libraries. Those are required to be able
to use the NDK.
Expand Down
51 changes: 40 additions & 11 deletions build-android.sh
Expand Up @@ -151,16 +151,29 @@ if [ -d "$PROGDIR/$BUILD_DIR" ]; then
fi


export AndroidNDKRoot=$PARAMETERS
AndroidNDKRoot=$PARAMETERS
if [ -z "$AndroidNDKRoot" ] ; then
if [ -z "`which ndk-build`" ]; then
dump "ERROR: You need to provide a <ndk-root>!"
exit 1
fi
AndroidNDKRoot=`which ndk-build`
AndroidNDKRoot=`dirname $AndroidNDKRoot`
echo "Using AndroidNDKRoot = $AndroidNDKRoot"
if [ -n "${ANDROID_BUILD_TOP}" ]; then # building from Android sources
AndroidNDKRoot="${ANDROID_BUILD_TOP}/prebuilts/ndk/current"
export AndroidSourcesDetected=1
elif [ -z "`which ndk-build`" ]; then
dump "ERROR: You need to provide a <ndk-root>!"
exit 1
else
AndroidNDKRoot=`which ndk-build`
AndroidNDKRoot=`dirname $AndroidNDKRoot`
fi
echo "Using AndroidNDKRoot = $AndroidNDKRoot"
else
# User passed the NDK root as a parameter. Make sure the directory
# exists and make it an absolute path.
if [ ! -f "$AndroidNDKRoot/ndk-build" ]; then
dump "ERROR: $AndroidNDKRoot is not a valid NDK root"
exit 1
fi
AndroidNDKRoot=$(cd $AndroidNDKRoot; pwd -P)
fi
export AndroidNDKRoot

# Check platform patch
case "$HOST_OS" in
Expand All @@ -178,7 +191,20 @@ case "$HOST_OS" in
esac

NDK_RELEASE_FILE=$AndroidNDKRoot"/RELEASE.TXT"
NDK_RN=`cat $NDK_RELEASE_FILE | sed 's/^r\(.*\)$/\1/g'`
if [ -f "${NDK_RELEASE_FILE}" ]; then
NDK_RN=`cat $NDK_RELEASE_FILE | sed 's/^r\(.*\)$/\1/g'`
elif [ -n "${AndroidSourcesDetected}" ]; then
NDK_RELEASE_FILE="${ANDROID_BUILD_TOP}/ndk/docs/CHANGES.html"
if [ -f "${NDK_RELEASE_FILE}" ]; then
NDK_RN=`grep "android-ndk-" "${NDK_RELEASE_FILE}" | head -1 | sed 's/^.*r\(.*\)$/\1/'`
else
dump "ERROR: can not find ndk version"
exit 1
fi
else
dump "ERROR: can not find ndk version"
exit 1
fi

echo "Detected Android NDK version $NDK_RN"

Expand Down Expand Up @@ -208,7 +234,7 @@ case "$NDK_RN" in
CXXPATH=$AndroidNDKRoot/toolchains/${TOOLCHAIN}/prebuilt/$PlatformOS-x86/bin/arm-linux-androideabi-g++
TOOLSET=gcc-androidR8b
;;
8e|9|9b)
8e|9|9b|9c|9d)
TOOLCHAIN=${TOOLCHAIN:-arm-linux-androideabi-4.6}
CXXPATH=$AndroidNDKRoot/toolchains/${TOOLCHAIN}/prebuilt/$PlatformOS-x86/bin/arm-linux-androideabi-g++
TOOLSET=gcc-androidR8e
Expand All @@ -218,7 +244,7 @@ case "$NDK_RN" in
CXXPATH=$AndroidNDKRoot/toolchains/${TOOLCHAIN}/prebuilt/${PlatformOS}-x86_64/bin/arm-linux-androideabi-g++
TOOLSET=gcc-androidR8e
;;
"9 (64-bit)"|"9b (64-bit)")
"9 (64-bit)"|"9b (64-bit)"|"9c (64-bit)"|"9d (64-bit)")
TOOLCHAIN=${TOOLCHAIN:-arm-linux-androideabi-4.6}
CXXPATH=$AndroidNDKRoot/toolchains/${TOOLCHAIN}/prebuilt/${PlatformOS}-x86_64/bin/arm-linux-androideabi-g++
TOOLSET=gcc-androidR8e
Expand All @@ -228,6 +254,9 @@ case "$NDK_RN" in
exit 1
esac

if [ -n "${AndroidSourcesDetected}" ]; then # Overwrite CXXPATH if we are building from Android sources
CXXPATH="${ANDROID_TOOLCHAIN}/arm-linux-androideabi-g++"
fi

echo Building with TOOLSET=$TOOLSET CXXPATH=$CXXPATH CXXFLAGS=$CXXFLAGS | tee $PROGDIR/build.log

Expand Down
12 changes: 12 additions & 0 deletions patches/boost-1_53_0/boost-1_53_0.patch
@@ -1,3 +1,15 @@
diff -ruN boost_1_54_0/libs/filesystem/src/path.cpp boost_1_54_0_patched/libs/filesystem/src/path.cpp
--- boost_1_54_0/libs/filesystem/src/path.cpp 2012-04-16 15:36:28.000000000 +0200
+++ boost_1_54_0_patched/libs/filesystem/src/path.cpp 2013-10-28 02:55:32.773380890 +0100
@@ -902,7 +902,7 @@

const path::codecvt_type& path::codecvt()
{
-# if defined(BOOST_POSIX_API) && \
+# if defined(BOOST_POSIX_API) && !defined(__ANDROID__) && \
!(defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
// A local static initialized by calling path::imbue ensures that std::locale(""),
// which may throw, is called only if path_locale and condecvt_facet will actually
diff -ruN boost_1_53_0-boot/boost/asio/detail/socket_types.hpp boost_1_53_0-patched/boost/asio/detail/socket_types.hpp
--- boost_1_53_0-boot/boost/asio/detail/socket_types.hpp 2012-01-15 14:46:25.000000000 +0100
+++ boost_1_53_0-patched/boost/asio/detail/socket_types.hpp 2012-06-27 19:19:01.279562338 +0200
Expand Down
12 changes: 12 additions & 0 deletions patches/boost-1_54_0/boost-1_54_0.patch
@@ -1,3 +1,15 @@
diff -ruN boost_1_54_0/libs/filesystem/src/path.cpp boost_1_54_0_patched/libs/filesystem/src/path.cpp
--- boost_1_54_0/libs/filesystem/src/path.cpp 2012-04-16 15:36:28.000000000 +0200
+++ boost_1_54_0_patched/libs/filesystem/src/path.cpp 2013-10-28 02:55:32.773380890 +0100
@@ -902,7 +902,7 @@

const path::codecvt_type& path::codecvt()
{
-# if defined(BOOST_POSIX_API) && \
+# if defined(BOOST_POSIX_API) && !defined(__ANDROID__) && \
!(defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
// A local static initialized by calling path::imbue ensures that std::locale(""),
// which may throw, is called only if path_locale and condecvt_facet will actually
diff -ruN boost_1_54_0-boot/boost/asio/detail/socket_types.hpp boost_1_54_0-patched/boost/asio/detail/socket_types.hpp
--- boost_1_54_0-boot/boost/asio/detail/socket_types.hpp
+++ boost_1_54_0-patched/boost/asio/detail/socket_types.hpp
Expand Down

0 comments on commit 8075d96

Please sign in to comment.