Enable C++11 support on Android Enable C++11 support on Android android android

Enable C++11 support on Android


It appears the main answer here includes experimental support for C++11, and C++11 is not experimental anymore.

If you're using command line NDK support (I use IDEA community edition 13 for the Java stuff), then this is what I had to put in my jni/Application.mk to get C++11 support with API 19 (on OSX ML):

NDK_TOOLCHAIN_VERSION := 4.8# APP_STL := stlport_shared  --> does not seem to contain C++11 featuresAPP_STL := gnustl_shared# Enable c++11 extentions in source codeAPP_CPPFLAGS += -std=c++11

Derived from here and here.


First of all, you will need to ensure that your toolchain is "Cross GCC". Whilst it was the default on my Linux, it was not on my MacOSX Lion.

In order to do this, go to Project Properties > C/C++ Build > Tool Chain Editor. "Current toolchain" should be set to "Cross GCC". You might need to uncheck the box "Display compatible toolchains only".

Then, add an option to LOCAL_CFLAGS in Android.mk:

LOCAL_CFLAGS := -std=gnu++11

We now need to inform Eclipse about where to find the corresponding new symbols (e.g. "std::unordered_map"). Go to Right Click on "jni" > Properties > C/C++ General -> Paths and Symbols -> Symbols -> GNU C++, and add the following symbol (by clicking "Add..."):

Name: __GXX_EXPERIMENTAL_CXX0X__Value:

(i.e. let "Value" empty)


You can also set this in your build.gradle file if you are using the gradle-experimental-plugin:

android.ndk {    moduleName = "hello-android-jni"    stl = "stlport_shared"    cppFlags.add("-std=c++11")}