Index: /pjproject/trunk/aconfigure
===================================================================
--- /pjproject/trunk/aconfigure	(revision 6119)
+++ /pjproject/trunk/aconfigure	(revision 6120)
@@ -9023,4 +9023,7 @@
 			    	ac_webrtc_instset=mips
 			        ;;
+			    x86*)
+				ac_webrtc_instset=sse2
+			    	;;
 			    *)
 				ac_webrtc_instset=generic
Index: /pjproject/trunk/aconfigure.ac
===================================================================
--- /pjproject/trunk/aconfigure.ac	(revision 6119)
+++ /pjproject/trunk/aconfigure.ac	(revision 6120)
@@ -2085,4 +2085,7 @@
 			    	ac_webrtc_instset=mips
 			        ;;
+			    x86*)
+			    	ac_webrtc_instset=sse2
+			    	;;
 			    *)
 				ac_webrtc_instset=generic
Index: /pjproject/trunk/configure-android
===================================================================
--- /pjproject/trunk/configure-android	(revision 6119)
+++ /pjproject/trunk/configure-android	(revision 6120)
@@ -67,8 +67,12 @@
   ADD_CFLAGS="0"
   ADD_CXXFLAGS="0"
+  ADD_LDFLAGS="0"
   ADD_NDK_TOOLCHAIN="0"
   ADD_NDK_TARGET="0"
   if test "x${IGNORE_CFLAGS}" = "x"; then
-    IGNORE_CFLAGS="\-M\|\-f*stack\|\-f*alias\|\-\<g\>"
+    IGNORE_CFLAGS="\-M\|\-f*stack\|\-f*alias\|\-\<g\>\|\-DNDEBUG\|\-O"
+  fi
+  if test "x${IGNORE_CPPFLAGS}" = "x"; then
+    IGNORE_CPPFLAGS="\-M\|\-f*stack\|\-f*alias\|\-\<g\>\|\-DNDEBUG\|\-O\|\-std\="
   fi
   
@@ -85,7 +89,7 @@
   fi
 
-   echo "====="
-   echo "NDK_OUT : ${NDK_OUT}"
-   echo "====="
+  #echo "====="
+  #echo "NDK_OUT : ${NDK_OUT}"
+  #echo "====="
 
   for i in $NDK_OUT; do
@@ -97,11 +101,13 @@
         continue
       fi
+      if test "$i" = "-c"; then
+        continue
+      fi
       if test "x`echo $i|grep 'dummy'`" != "x"; then
         continue
       fi
-      if test "x`echo $i|grep '\-\-sysroot='`" != "x"; then
-        ANDROID_SYSROOT=`echo $i|sed 's/--sysroot=//'`;
-      fi
-      NDK_CXXFLAGS="${NDK_CXXFLAGS} $i"
+      if test "x`echo $i|grep ${IGNORE_CPPFLAGS}`" = "x"; then
+        NDK_CXXFLAGS="${NDK_CXXFLAGS} $i"
+      fi
       continue
     fi
@@ -133,4 +139,20 @@
     fi
 
+    # Parse NDK LDFLAGS
+    if test "${ADD_LDFLAGS}" = "1"; then
+      if test "$i" = "-o"; then
+        ADD_LDFLAGS="0"
+        continue
+      fi
+      if test "x`echo $i|grep 'dummy'`" != "x"; then
+        continue
+      fi
+      if test "x`echo $i|grep '.so'`" != "x"; then
+        continue
+      fi
+      NDK_LDFLAGS="${NDK_LDFLAGS} $i"
+      continue
+    fi
+
     # Find gcc or clang
     if test "x${NDK_CC}" = "x"; then
@@ -142,4 +164,5 @@
 	  #echo "---using llvm"
 	fi
+	continue
       fi
     fi
@@ -150,21 +173,32 @@
         NDK_CXX=$i
         ADD_CXXFLAGS="1"
+	continue
+      fi
+    fi
+
+    # Find linking/LDFLAGS
+    if test "x${NDK_LDFLAGS}" = "x"; then
+      if test "x`echo $i | grep '\-\<shared\>'`" != "x"; then
+        ADD_LDFLAGS="1"
+	continue
       fi
     fi
 
     # Find ar tool
-    if test "x${NDK_AR}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-ar'`" != "x"; then
-      if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then
+    if test "x${NDK_AR}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-\<ar\>'`" != "x"; then
+      # In some NDKs, e.g: r17c, gcc/clang and ar have different path
+      #if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then
         NDK_AR=$i
         #echo "--- found AR=${NDK_AR}"
-      fi
+	continue
+      #fi
     fi
 
     # Find ranlib tool
-    if test "x${NDK_RANLIB}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-ranlib'`" != "x"; then
-      if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then
+    if test "x${NDK_RANLIB}" = "x" -a "x${NDK_CC}" != "x" -a "x`echo $i|grep '\-\<ranlib\>'`" != "x"; then
+      #if test "$(dirname \"${NDK_CC}\")" = "$(dirname \"${i}\")"; then
         NDK_RANLIB=$i
         #echo "--- found RANLIB=${NDK_RANLIB}"
-      fi
+      #fi
     fi
   done
@@ -193,5 +227,5 @@
       NDK_AR=`find ${NDK_CC_DIR} -name "*ar" | grep -m 1 -v "gcc"`
     fi
-    export LDFLAGS="${LDFLAGS} --sysroot=${ANDROID_SYSROOT}"
+    export LDFLAGS="${LDFLAGS}"
   else
     # find ar and ranlib
@@ -202,5 +236,5 @@
       NDK_RANLIB=`find ${NDK_TOOLCHAIN}/bin/ -name "*-ranlib" | grep -m 1 -v "gcc"`
     fi
-    export LDFLAGS="${LDFLAGS} --sysroot=${ANDROID_SYSROOT} -target ${NDK_TARGET} -gcc-toolchain ${NDK_TOOLCHAIN}"
+    export LDFLAGS="${LDFLAGS} -target ${NDK_TARGET} -gcc-toolchain ${NDK_TOOLCHAIN}"
   fi
 
@@ -220,8 +254,9 @@
   export CXX="${NDK_CXX}"
 
-  export LIBS="${LIBS} -lc -lgcc -ldl"
+  export LDFLAGS="${NDK_LDFLAGS}"
+  export LIBS="${LIBS}"
   export CFLAGS="${NDK_CFLAGS} ${CFLAGS}"
-  export CPPFLAGS="${CFLAGS} -fexceptions -frtti"
-  export CXXFLAGS="${NDK_CXXFLAGS} -fexceptions -frtti"
+  export CPPFLAGS="${NDK_CXXFLAGS} ${CPPFLAGS}"
+  export CXXFLAGS="${CPPFLAGS}"
 
 else
@@ -272,7 +307,8 @@
   # llvm
   STDCPP_TC="${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++"
-  STDCPP_CFLAGS="-I${STDCPP_TC}/include"
-  STDCPP_LIBS="-lc++_static -lc++abi"
-  STDCPP_LDFLAGS="-L${STDCPP_TC}/libs/${TARGET_ABI}/"
+  #STDCPP_CFLAGS="-I${STDCPP_TC}/include"
+  #STDCPP_LIBS="-lc++_static -lc++abi"
+  STDCPP_LIBS="${STDCPP_TC}/libs/${TARGET_ABI}/libc++_shared.so"
+  #STDCPP_LDFLAGS="-L${STDCPP_TC}/libs/${TARGET_ABI}/"
 else
   # gnustl
@@ -291,4 +327,6 @@
 export LIBS="${STDCPP_LIBS} ${LIBS}"
 export LDFLAGS="${LDFLAGS} ${STDCPP_LDFLAGS}"
+export CPPFLAGS="${CPPFLAGS} ${STDCPP_CFLAGS}"
+export CXXFLAGS="${CPPFLAGS}"
 
 # Print settings
Index: /pjproject/trunk/pjsip-apps/src/samples/android_sample/jni/Android.mk
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/android_sample/jni/Android.mk	(revision 6119)
+++ /pjproject/trunk/pjsip-apps/src/samples/android_sample/jni/Android.mk	(revision 6120)
@@ -2,8 +2,6 @@
 
 include $(CLEAR_VARS)
-
 LOCAL_MODULE    := dummy_static
-LOCAL_SRC_FILES := dummy.c
-
+LOCAL_SRC_FILES := dummy.c dummy2.cc
 include $(BUILD_STATIC_LIBRARY)
 
@@ -11,5 +9,4 @@
 LOCAL_MODULE	:= dummy_shared
 LOCAL_STATIC_LIBRARIES := dummy_static
-LOCAL_SRC_FILES := dummy.c
-
+LOCAL_SRC_FILES := dummy.c dummy2.cc
 include $(BUILD_SHARED_LIBRARY)
Index: /pjproject/trunk/pjsip-apps/src/samples/android_sample/jni/Application.mk
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/android_sample/jni/Application.mk	(revision 6119)
+++ /pjproject/trunk/pjsip-apps/src/samples/android_sample/jni/Application.mk	(revision 6120)
@@ -1,1 +1,3 @@
 APP_ABI := all
+APP_CPPFLAGS := -fexceptions -frtti
+APP_STL := c++_shared
Index: /pjproject/trunk/pjsip-apps/src/samples/android_sample/jni/dummy2.cc
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/android_sample/jni/dummy2.cc	(revision 6120)
+++ /pjproject/trunk/pjsip-apps/src/samples/android_sample/jni/dummy2.cc	(revision 6120)
@@ -0,0 +1,11 @@
+#include <string>
+#include <stdint.h>
+#include <math.h>
+
+int main() {
+  uint64_t	blah = 0;
+  size_t	blah2 = 1;
+  std::string	blah3 = "3";
+  
+  return 0;
+}
Index: /pjproject/trunk/pjsip-apps/src/swig/java/Makefile
===================================================================
--- /pjproject/trunk/pjsip-apps/src/swig/java/Makefile	(revision 6119)
+++ /pjproject/trunk/pjsip-apps/src/swig/java/Makefile	(revision 6120)
@@ -164,7 +164,9 @@
 ifeq ($(OS),android)
 	mkdir -p android/app/src/main/jniLibs/$(TARGET_ARCH)
+	# copy libc++_shared.so manually
+	cp -f ${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TARGET_ARCH}/libc++_shared.so android/app/src/main/jniLibs/$(TARGET_ARCH)
 endif
 	$(PJ_CXX) -shared -o $(LIBPJSUA2_SO) $(OUT_DIR)/pjsua2_wrap.o \
-		$(MY_CFLAGS) $(MY_LDFLAGS)
+		$(MY_LDFLAGS)
 
 $(OUT_DIR)/pjsua2_wrap.o: $(OUT_DIR)/pjsua2_wrap.cpp Makefile
Index: /pjproject/trunk/pjsip-apps/src/swig/java/android/app/build.gradle
===================================================================
--- /pjproject/trunk/pjsip-apps/src/swig/java/android/app/build.gradle	(revision 6119)
+++ /pjproject/trunk/pjsip-apps/src/swig/java/android/app/build.gradle	(revision 6120)
@@ -13,4 +13,10 @@
             moduleName "libpjsua2"
         }
+
+        externalNativeBuild {
+            cmake {
+                arguments "-DANDROID_STL=c++_shared"
+            }
+        }
     }
 
Index: /pjproject/trunk/pjsip/build/Makefile
===================================================================
--- /pjproject/trunk/pjsip/build/Makefile	(revision 6119)
+++ /pjproject/trunk/pjsip/build/Makefile	(revision 6120)
@@ -47,6 +47,10 @@
 		   $(CC_INC)../../pjnath/include \
 		   $(CC_INC)../../pjmedia/include
-export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
-		   $(HOST_CXXFLAGS) $(CXXFLAGS)
+export _CXXFLAGS:= $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
+		   $(HOST_CXXFLAGS) $(CXXFLAGS) $(CC_INC)../include \
+		   $(CC_INC)../../pjlib/include \
+		   $(CC_INC)../../pjlib-util/include \
+		   $(CC_INC)../../pjnath/include \
+		   $(CC_INC)../../pjmedia/include
 export _LDFLAGS := $(APP_THIRD_PARTY_LIBS) \
 		   $(APP_THIRD_PARTY_EXT) \
@@ -141,5 +145,5 @@
 			   siptypes.o call.o presence.o media.o
 export PJSUA2_LIB_CFLAGS += $(_CFLAGS) $(PJ_VIDEO_CFLAGS)
-export PJSUA2_LIB_CXXFLAGS = $(_CXXFLAGS) $(PJSUA2_LIB_CFLAGS) 
+export PJSUA2_LIB_CXXFLAGS = $(_CXXFLAGS)
 export PJSUA2_LIB_LDFLAGS += $(PJSUA_LIB_LDLIB) \
 			     $(PJSIP_UA_LDLIB) \
Index: /pjproject/trunk/third_party/build/webrtc/Makefile
===================================================================
--- /pjproject/trunk/third_party/build/webrtc/Makefile	(revision 6119)
+++ /pjproject/trunk/third_party/build/webrtc/Makefile	(revision 6120)
@@ -21,5 +21,5 @@
 		   $(CFLAGS) $(CC_INC). $(CC_INC)../../webrtc/src       \
 		   $(CC_INC)../../../pjlib/include
-export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
+export _CXXFLAGS:= $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
 		   $(HOST_CXXFLAGS) $(CXXFLAGS)
 export _LDFLAGS := $(CC_LDFLAGS) $(OS_LDFLAGS) $(M_LDFLAGS) $(HOST_LDFLAGS) \
Index: /pjproject/trunk/third_party/build/yuv/Makefile
===================================================================
--- /pjproject/trunk/third_party/build/yuv/Makefile	(revision 6119)
+++ /pjproject/trunk/third_party/build/yuv/Makefile	(revision 6120)
@@ -20,6 +20,6 @@
 		   $(CFLAGS) $(CC_INC). $(CC_INC)../../yuv/include \
 		   $(CC_INC)../../../pjlib/include
-export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
-		   $(HOST_CXXFLAGS) $(CXXFLAGS)
+export _CXXFLAGS:= $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
+		   $(HOST_CXXFLAGS) $(CXXFLAGS) $(CC_INC). $(CC_INC)../../yuv/include
 export _LDFLAGS := $(CC_LDFLAGS) $(OS_LDFLAGS) $(M_LDFLAGS) $(HOST_LDFLAGS) \
 		   $(LDFLAGS) 
