Index: pjproject/branches/projects/pjsua2/configure-android
===================================================================
--- pjproject/branches/projects/pjsua2/configure-android	(revision 4696)
+++ pjproject/branches/projects/pjsua2/configure-android	(revision 4697)
@@ -87,7 +87,7 @@
   export CXX="${NDK_CXX}"
 
-  export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/ -L${ANDROID_NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi"
-  export LIBS="${LIBS} -lgnustl_static -lc -lgcc ${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o"
-  export CFLAGS="${CFLAGS} ${NDK_CFLAGS} -I${ANDROID_NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.7/include -I${ANDROID_NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi/include"
+  export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/"
+  export LIBS="${LIBS} -lc -lgcc"
+  export CFLAGS="${CFLAGS} ${NDK_CFLAGS}"
   export CPPFLAGS="${CFLAGS} -fexceptions -frtti"
   export CXXFLAGS="${NDK_CXXFLAGS} -fexceptions -frtti"
@@ -111,11 +111,29 @@
   export CXX="${ANDROID_TC}/bin/${TARGET_HOST}-g++"
 
-  export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/ -L${ANDROID_NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi"
-  export LIBS="${LIBS} -lgnustl_static -lc -lgcc ${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o"
-  export CFLAGS="${CFLAGS} -I${ANDROID_SYSROOT}/usr/include -I${ANDROID_NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.7/include -I${ANDROID_NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi/include"
+  export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/"
+  export LIBS="${LIBS} -lc -lgcc"
+  export CFLAGS="${CFLAGS} -I${ANDROID_SYSROOT}/usr/include"
   export CPPFLAGS="${CFLAGS} -fexceptions -frtti"
   export CXXFLAGS="${CXXFLAGS} -shared --sysroot=${ANDROID_SYSROOT} -fexceptions -frtti"
 
 fi
+
+# C++ STL
+# Note: STL for pjsua2 sample app is specified in pjsip-apps/src/swig/java/android/jni/Application.mk
+
+# gnustl
+STDCPP_TC_VER=`ls -d ${ANDROID_NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/[0-9]* | sort -gr | head -1`
+STDCPP_CFLAGS="-I${STDCPP_TC_VER}/include -I${STDCPP_TC_VER}/libs/armeabi/include"
+STDCPP_LIBS="${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o -lgnustl_static"
+STDCPP_LDFLAGS="-L${STDCPP_TC_VER}/libs/armeabi"
+
+# stlport
+#STDCPP_CFLAGS="-I${ANDROID_NDK_ROOT}/sources/cxx-stl/stlport/stlport"
+#STDCPP_LIBS="${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o -lstlport_static -ldl"
+#STDCPP_LDFLAGS="-L${ANDROID_NDK_ROOT}/sources/cxx-stl/stlport/libs/armeabi"
+
+export CFLAGS="${CFLAGS} ${STDCPP_CFLAGS}"
+export LIBS="${STDCPP_LIBS} ${LIBS}"
+export LDFLAGS="${LDFLAGS} ${STDCPP_LDFLAGS}"
 
 # Print settings
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/AndroidManifest.xml
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/AndroidManifest.xml	(revision 4696)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/AndroidManifest.xml	(revision 4697)
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/jni/Android.mk
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/jni/Android.mk	(revision 4697)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/jni/Android.mk	(revision 4697)
@@ -0,0 +1,12 @@
+include ../../../../../build.mak
+
+LOCAL_PATH	:= $(PJDIR)/pjsip-apps/src/swig/java/android
+include $(CLEAR_VARS)
+
+LOCAL_MODULE    := libpjsua2
+LOCAL_CFLAGS    := $(APP_CFLAGS) -frtti -fexceptions
+LOCAL_LDFLAGS   := $(APP_LDFLAGS)
+LOCAL_LDLIBS    := $(APP_LDLIBS)
+LOCAL_SRC_FILES := $(PJDIR)/pjsip-apps/src/swig/java/output/pjsua2_wrap.cpp
+
+include $(BUILD_SHARED_LIBRARY)
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/jni/Application.mk
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/jni/Application.mk	(revision 4697)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/jni/Application.mk	(revision 4697)
@@ -0,0 +1,1 @@
+APP_STL := gnustl_static
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MainActivity.java
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MainActivity.java	(revision 4696)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MainActivity.java	(revision 4697)
@@ -26,4 +26,5 @@
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.pm.ApplicationInfo;
 import android.view.LayoutInflater;
 import android.view.Menu;
@@ -83,4 +84,11 @@
 		if (app == null) {
 			app = new MyApp();
+			/* Wait for GDB to init */
+			if ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
+				try {
+					Thread.sleep(5000);
+				} catch (InterruptedException e) {}
+			}
+			
 		    app.init(this, getFilesDir().getAbsolutePath());
 		}
@@ -128,5 +136,4 @@
 	@Override
 	public boolean onOptionsItemSelected(MenuItem item) {
-		CharSequence str = item.getTitle();
 		switch (item.getItemId()) {
 		case R.id.action_acc_config:
@@ -368,5 +375,5 @@
 						buddyListSelectedIdx = -1;
 			    	} else {
-			    		if (old_cfg.getUri() != cfg.getUri()) {
+			    		if (!old_cfg.getUri().equals(cfg.getUri())) {
 			    			account.delBuddy(buddyListSelectedIdx);
 			    			account.addBuddy(cfg);
Index: pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MyApp.java
===================================================================
--- pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MyApp.java	(revision 4696)
+++ pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MyApp.java	(revision 4697)
@@ -168,5 +168,5 @@
 			if (bi.getPresStatus().getStatus() == pjsua_buddy_status.PJSUA_BUDDY_STATUS_ONLINE) {
 				status = bi.getPresStatus().getStatusText();
-				if (status == null || status == "") {
+				if (status == null || status.isEmpty()) {
 					status = "Online";
 				}
@@ -340,5 +340,4 @@
 	public void delAcc(MyAccount acc) {
 		accList.remove(acc);
-		/* GC will delete the acc soon? */
 	}
 	
@@ -369,4 +368,9 @@
 			System.out.println(e);
 		}
+		
+		/* Suggest to delete, as we found this causes crash when the Java
+		 * deletes it later after lib has been destroyed.
+		 */
+		json.delete();
 	}
 
@@ -410,4 +414,9 @@
 			json.saveFile(filename);
 		} catch (Exception e) {}
+
+		/* Suggest to delete, as we found this causes crash when the Java
+		 * deletes it later after lib has been destroyed.
+		 */
+		json.delete();
 	}
 	
@@ -415,4 +424,10 @@
 		String configPath = appDir + "/" + configName;
 		saveConfig(configPath);
+		
+		/* Try force GC to avoid late destroy of PJ objects as they should be
+		 * deleted before lib is destroyed.
+		 */
+		System.gc();
+		
 		try {
 			ep.libDestroy();
