51

This question is in continuation to 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/

Include Boost C++ library in android

How to use the boost library (including shared_ptr) with the Android NDK and STLport

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

Android NDK R5 and support of C++ exception

Thanks in advance.

Community
  • 1
  • 1
Rohit
  • 6,941
  • 17
  • 58
  • 102
  • Technically you'd want official support for those platforms instead of _ports_. – K-ballo Dec 26 '12 at 05:26
  • is boost advisable for smartphone application development at all? – Rohit Dec 26 '12 at 07:02
  • 3
    FWIW, I successfully built my application (which uses boost quite extensively) both for iOS and for Android. I believe the main reason for the lack of "official" support is the fact that no one volunteered to run release tests for these platform. – Igor R. Dec 26 '12 at 09:13
  • 3
    ...as for "network intense application which spawns multple threads for commuication" -- you can use Boost.Asio and switch from "multiple threads" with all their mess and obverhead to much better Asio proactive model. – Igor R. Dec 26 '12 at 09:18
  • Hi Igor R.--> i suppose we require boost_filesytem.a for Boost.Asio, but i couldnot get the same using method provided in http://www.codexperiments.com/android/2011/05/tips-tricks-building-boost-with-ndk-r5/. can you please let me know the procedure how you compiled it? – Rohit Dec 26 '12 at 10:54
  • Also, can you please share your application names (if they are on google play or Appstore) – Rohit Dec 26 '12 at 10:57
  • @RDX No, Boost.Filesystem is absolutely unrelated to Boost.Asio. Our application is a client for some proprietary server, it won't work if you don't have one. – Igor R. Dec 26 '12 at 10:57
  • @RDX Asio is header-only, you don't have build it (although, it depends on Boost.System, which should be built). I built boost libs using the setting very similar to those appearing under the link you posted. What errors do you see when building boost? – Igor R. Dec 26 '12 at 11:18
  • i am trying to build echo client, it requires libboost_filesystem.a but we are not able to build this library, it throws libboost_filesystem.a(clean) for lack of – Rohit Dec 26 '12 at 11:35
  • i realized that to build echo client server, we would require libboost_system.a would test with the same. – Rohit Dec 26 '12 at 12:25
  • Hey where you able to use boost::asio on iOS without any issues ? – nnrales Apr 02 '18 at 02:35

4 Answers4

25

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

Rohit
  • 6,941
  • 17
  • 58
  • 102
  • 3
    I would happily put some of my work's hardware to use by running nightly regression tests. The problem is that the compilation is cross platform, has specific requirements for making applications (you cant just make a console application on these platforms), and the tests need to be run on an external device/simulator/emulator. The existing test suite is just not equipped for this, as far as I know. I would, however, be willing to work with someone, more familiar with boost testing than I, towards this endeavor. My first name (at) brainiumstudios.com – Brent Feb 08 '13 at 21:49
  • 4
    CrystaX https://www.crystax.net/ project launched regular regression tests for Android since March'15 http://www.boost.org/development/tests/master/developer/summary.html http://habrahabr.ru/post/253233/ (rus) – Olexij Moroz Jun 12 '15 at 08:21
17

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

markshiz
  • 2,501
  • 22
  • 28
12

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 :-)).

Peter Jankuliak
  • 3,464
  • 1
  • 29
  • 40
  • which boost libraries would be required for networking and multithreaded support? – Rohit Dec 31 '12 at 11:49
  • Add these three libraries: -lboost_system-gcc-mt-, -lboost_thread-gcc-mt- and -lgnustl_static (in that order). That should do it. Let us see the exact error you're seeing, it's hard to guess how to help without it. Additional info that would help us: NDK version, platform on which you're developing and whether you're using eclipse or ant+makefiles. – Peter Jankuliak Dec 31 '12 at 14:59
  • Thanks peter. Resolved the issues after analysing ur reply. One query.how did u complied boost on android? And r u using boost 1_52 – Rohit Jan 01 '13 at 10:08
  • @RDX, I've made an edit to my post, please have a look. The latest version of boost supported by Boost-for-Android is currently 1.49. – Peter Jankuliak Jan 01 '13 at 19:11
  • @RDX, or perhaps I misunderstood your question about 'compiling **on** android'. Did you mean to ask how to perform the compilation of boost inside an android device? In such case you don't need to do that (it would be extremely painful), you just need to make sure that the libraries you use from Boost-For-Android go inside the apk file. How to do this depends whether you're using makefiles or eclipse. For example if you used the Android.mk as mentioned above, this would be automatic. – Peter Jankuliak Jan 02 '13 at 07:13
11

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.

  1. 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!

sehe
  • 374,641
  • 47
  • 450
  • 633
Rohit
  • 6,941
  • 17
  • 58
  • 102