Official "Boost library" Support for Android and iOS?

AndroidIosBoostAndroid NdkBoost Asio

Android Problem Overview


This question is in continuation to https://stackoverflow.com/questions/13861115/should-i-choose-boost-asio-or-aysnc-socket-threads-in-android asked,

Boost libraries are intended to be widely useful, and usable across a broad range of applications, but yet there is no official support available for Android and iOS

  1. Is there any specific reason behind the same like Not optimized for embedded devices? Or any other reason?
  2. Does any body know of any application built using Boost on Android or iOS?
  3. Is it advisable to use boost libraries for network intense application which spawns multple threads for commuication?

FYI..I have been using following links to create a sample Android application , but not successful yet :(

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

http://www.codexperiments.com/android/2011/05/tips-tricks-building-boost-with-ndk-r5/

https://stackoverflow.com/questions/7885384/include-boost-c-library-in-android

https://stackoverflow.com/questions/4347151/how-to-use-the-boost-library-including-shared-ptr-with-the-android-ndk-and-stl

https://sites.google.com/site/fourdollars/android/android-mk

https://groups.google.com/forum/?fromgroups=#!topic/android-ndk/4lxhsKFe7Ho

http://www.crystax.net/trac/ndk/ticket/6

https://stackoverflow.com/questions/4663291/android-ndk-r5-and-support-of-c-exception

Thanks in advance.

Android Solutions


Solution 1 - Android

Got reply from boost community Yes. These platforms are not officially supported because no one has volunteered to run regression tests regularly for them.

It is not possible for a Boost developer to test on all platforms. So developers depend on the test results of regression tests run by volunteers. For example, see http://beta.boost.org/development/tests/trunk/developer/summary.html

If no one volunteers to run the tests for a particular platform, that platform is not officially supported.

So if you care about Android or iOS becoming officially supported, start running regular (preferably daily) regression tests for Boost. See http://beta.boost.org/development/running_regression_tests.html

Solution 2 - Android

Check out my cross-platform-tutorial on github. It shows you how to set up Boost and use it between iOS and Android. I had such a horrible time with this, I figure I'd document it so no one else had to figure it out. You'll notice that this project also pulls in several other common items used between the two platforms, e.g., CoreFoundation and SQLite.

https://github.com/markshiz/cross-platform-tutorial

Note: My tutorial does not show how to build the compiled libraries for boost. I have done that before with success using the instructions you provided:

http://www.codexperiments.com/android/2011/05/tips-tricks-building-boost-with-ndk-r5/

After you have a static library compiled by the Android toolchain, you can easily link it in via a module similar to those under the include/[NAME OF NEW SUBMODULE] directory of the project above. Use something similar to the following for the Android.mk file in the root of that directory.

include $(CLEAR_VARS)
LOCAL_MODULE:= boost_regex
LOCAL_SRC_FILES:= ./path/to/built/static/library/libboost_regex-gcc-mt-s.a
LOCAL_EXPORT_C_INCLUDES := ./path/to/the/directory/that/has/the/boost/headers
include $(PREBUILT_STATIC_LIBRARY)

Finally, import that module, as in the example, inside

$(call import-module,[NAME OF NEW SUBMODULE])

As far your other questions --do you know of an application that uses Boost on iOS and Android? Yes, I have done it multiple times with success and released working apps to the App Stores.

Your other question, is it advisable to use boost for network communication? I'm not sure what you mean here. From what angle? Do you mean, philosophically, technically, etc?

Philosophically, you have to ask yourself, what is your reasoning for importing this library and using it between Android and iOS. Is it to save code time, maintenance burden. If so, I'd say this is an excellent way to do that. Clearly there are some hurdles and pain to get this sort of a set up working. Also, the IDE features for C++ aren't as awesome as for Java in Eclipse. I try to be fair and balanced in the PDF presentation in the doc/ directory. Give that a once over.

From a technical perspective, I think the only thing I would be worried about is making sure I clean up the Asio objects properly when the Activity is stopped. If you need to do things in the background, use a Service instead:

http://developer.android.com/reference/android/app/Service.html

Solution 3 - Android

UPDATE: There seems to be a problem with std::atomic on Android, and since Boost.Asio is using it (by default), combined with threads, one occasionally got deadlocked. Fortunately Boost.Asio makes it easy to switch from Std.Atomic to Boost.Atomic and this has been taken care of in the Boost-for-Android project in this commit.

For more info about the bug, see here


We are developing a simple multiplayer game (not yet released) for Android using boost asio and so far we did not have any problems. That's for the question #2.

What kind of problems are you seeing?

If the problems are related to compiling and linking, perhaps these hints will prove useful.

Add following to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Have this in your Application.mk file:

APP_STL := gnustl_static
APP_CPPFLAGS += -frtti -fexceptions

And use this as a template for your Android.mk file:

LOCAL_PATH := $(call my-dir)
BOOST_VERSION      := 1_49
PROJECT_ROOT       := $(LOCAL_PATH)/../../../..
BOOST_INCLUDE_PATH := /path/to/boost/headers
BOOST_LIB_PATH     := /path/to/boost/libraries

# Path and name of the STL library. Add this to the *end* of LOCAL_LDLIBS.
# Note this is a hack/workaround to prevent linker errors when compiling with 
# boost. 
STL_LIBS :=	-L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/armeabi \
					-lgnustl_static

include $(CLEAR_VARS)

LOCAL_MODULE    := native-activity
LOCAL_C_INCLUDES:= $(BOOST_INCLUDE_PATH) \
	               $(PROJECT_ROOT)/src \
	               $(PROJECT_ROOT)/platform/android/jni

LOCAL_SRC_FILES := main.cpp
LOCAL_LDLIBS    := -llog -landroid

# The order of these libraries is often important.
LOCAL_LDLIBS += -L$(BOOST_LIB_PATH) 	\
	     		-lboost_system-gcc-mt-$(BOOST_VERSION)	\
	     		-lboost_thread-gcc-mt-$(BOOST_VERSION)	\
	     		$(STL_LIBS)

LOCAL_STATIC_LIBRARIES := android_native_app_glue

include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)

EDIT: How we build boost for Android. This is what we have in our Makefile:

git clone git://github.com/madadam/Boost-for-Android.git
./build-android.sh --boost=1.49.0 --with-libraries=chrono,program_options,system,thread /path/to/ndk

Note that we are using our own fork of Boost-for-Android, this is only because that one has a patch for the newest NDK version r8d. It can also be seen from the command line that we are using the 1.49 version of boost, this is currently the highest supported by Boost-for-Android.

If you would like to know what combinations of Boost and Android NDK are supported, have a look inside the Boost-for-Android project. It contains directories called patches/boost-<X>/ndk-android<Y> where X corresponds to the supported boost version and Y to the supported NDK version (shameless plug: our 2 cents to the project :-)).

Solution 4 - Android

Below are some more (Very useful) information received from boost community:

> 1. Is there any specific reason behind the same (like not optimized for > embedded devices)? Or any other reason?

Boost works perfectly on Android. As there is a NDK (native development kit) with a quite decent gcc (4.6 something) you just need to configure boost build to use the right gcc. Although this all works, it requires a little bit of tinkering to get the settings right. But again, in principle, there is not a lot of difference in building Boost for Android or any other linux distribution.

> 2. Are there (at all) any known issues if we use boost libraries for > networking and thread synchronization for Smartphone application > development ? Will it be a good idea to use BOOST ASIO for the same?

It is perfectly fine to use Boost.Thread or Boost.Asio. They work perfectly fine on ARM devices. There is even support for the more platform specific hackeries like boost.atomic and boost.context.

> FYI are the links found > https://github.com/MysticTreeGames/Boost-for-Android > http://www.codexperiments.com/android/2011/05/tips-tricks-building-boost-with-ndk-r5/

Building boost with the Android NDK is even simpler than with boost.build directly. I compiled a bunch of Android build scripts, which can be found here: https://github.com/STEllAR-GROUP/HPXAndroid/tree/master/modules Look for the boost_${module} for various boost libraries. This is not a complete list. Only what i needed. Also, might need some love for 1.53. All the different libraries didn't need any special android treatment (modulo some minor bugs where the compiler didn't agree with other gcc versions)

I hope this would be useful for others as well! Thanks!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRohitView Question on Stackoverflow
Solution 1 - AndroidRohitView Answer on Stackoverflow
Solution 2 - AndroidmarkshizView Answer on Stackoverflow
Solution 3 - AndroidPeter JankuliakView Answer on Stackoverflow
Solution 4 - AndroidRohitView Answer on Stackoverflow