From e062d51ea46e388241681e9a3997754872727b16 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Wed, 18 Dec 2013 11:42:04 +0000 Subject: [PATCH] Re #1716: Misc fixes/updates on Android app based on pjsua2+SWIG, e.g: fixed java string comparisons, added build config for ndk-build (for native debugging), updates on SVN props. git-svn-id: https://svn.pjsip.org/repos/pjproject/branches/projects/pjsua2@4697 74dad513-b988-da41-8d7b-12977e46ad98 --- configure-android | 30 +++++-- .../src/swig/java/android/AndroidManifest.xml | 88 +++++++++---------- .../src/swig/java/android/jni/Android.mk | 12 +++ .../src/swig/java/android/jni/Application.mk | 1 + .../org/pjsip/pjsua2/app/MainActivity.java | 11 ++- .../src/org/pjsip/pjsua2/app/MyApp.java | 19 +++- 6 files changed, 107 insertions(+), 54 deletions(-) create mode 100644 pjsip-apps/src/swig/java/android/jni/Android.mk create mode 100644 pjsip-apps/src/swig/java/android/jni/Application.mk diff --git a/configure-android b/configure-android index 448c17c26..8240fdbe2 100755 --- a/configure-android +++ b/configure-android @@ -86,9 +86,9 @@ if test "$1" = "--use-ndk-cflags"; then export CC="${NDK_CC}" 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" @@ -110,14 +110,32 @@ else export CC="${ANDROID_TC}/bin/${TARGET_HOST}-gcc" 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 if test "1" = "1"; then echo "$F: calling ./configure with env vars:" diff --git a/pjsip-apps/src/swig/java/android/AndroidManifest.xml b/pjsip-apps/src/swig/java/android/AndroidManifest.xml index 4ce477ab4..5a9b0aeff 100644 --- a/pjsip-apps/src/swig/java/android/AndroidManifest.xml +++ b/pjsip-apps/src/swig/java/android/AndroidManifest.xml @@ -1,44 +1,44 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pjsip-apps/src/swig/java/android/jni/Android.mk b/pjsip-apps/src/swig/java/android/jni/Android.mk new file mode 100644 index 000000000..b98ed0aff --- /dev/null +++ b/pjsip-apps/src/swig/java/android/jni/Android.mk @@ -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) diff --git a/pjsip-apps/src/swig/java/android/jni/Application.mk b/pjsip-apps/src/swig/java/android/jni/Application.mk new file mode 100644 index 000000000..87124dd88 --- /dev/null +++ b/pjsip-apps/src/swig/java/android/jni/Application.mk @@ -0,0 +1 @@ +APP_STL := gnustl_static diff --git a/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MainActivity.java b/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MainActivity.java index 78c89f85c..4ffc719cc 100644 --- a/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MainActivity.java +++ b/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MainActivity.java @@ -25,6 +25,7 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.ApplicationInfo; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -82,6 +83,13 @@ public class MainActivity extends Activity implements Handler.Callback, MyAppObs 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()); } @@ -127,7 +135,6 @@ public class MainActivity extends Activity implements Handler.Callback, MyAppObs @Override public boolean onOptionsItemSelected(MenuItem item) { - CharSequence str = item.getTitle(); switch (item.getItemId()) { case R.id.action_acc_config: dlgAccountSetting(); @@ -367,7 +374,7 @@ public class MainActivity extends Activity implements Handler.Callback, MyAppObs buddyListAdapter.notifyDataSetChanged(); buddyListSelectedIdx = -1; } else { - if (old_cfg.getUri() != cfg.getUri()) { + if (!old_cfg.getUri().equals(cfg.getUri())) { account.delBuddy(buddyListSelectedIdx); account.addBuddy(cfg); buddyList.remove(buddyListSelectedIdx); diff --git a/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MyApp.java b/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MyApp.java index eaccde7b9..35a2c362c 100644 --- a/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MyApp.java +++ b/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MyApp.java @@ -167,7 +167,7 @@ class MyBuddy extends Buddy { if (bi.getSubState() == pjsip_evsub_state.PJSIP_EVSUB_STATE_ACTIVE) { 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"; } } else if (bi.getPresStatus().getStatus() == pjsua_buddy_status.PJSUA_BUDDY_STATUS_OFFLINE) { @@ -339,7 +339,6 @@ class MyApp { public void delAcc(MyAccount acc) { accList.remove(acc); - /* GC will delete the acc soon? */ } private void loadConfig(String filename) { @@ -368,6 +367,11 @@ class MyApp { } catch (Exception e) { 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(); } private void buildAccConfigs() { @@ -409,11 +413,22 @@ class MyApp { /* Save file */ 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(); } public void deinit() { 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(); } catch (Exception e) {}