Port exosip toandroidplatform isn't a difficult task because exosip doesn't rely on any special system calls that aren't available onandroid. It only requiresosipto compile, which can also be easily ported.
As an example, I created two applications to run against exosip lib. One is a native application that can run inandroidshell, the other is an java application that interact with exosipthrough jni. The dependency relationship between modules is:


The diagram below depicts the organization of files. They're organized this way so that they can be compiled throughandroidndkbuild system.

exosip_root (NDK_MODULE_PATH environment variable points here)
  • libosip
    • Android.mk
    • source files
  • libexosip
    • Android.mk
    • source files
  • sip_exe
    • jni
      • Android.mk
      • Application.mk
      • source file
  • sip_jni
    • jni
      • Android.mk
      • source files
    • libs
      • armeabi
        • libosip.so
        • libexosip.so
    • src
      • java source files
    • AndroidManifest.xml

To comply with ndk build system's requirements, we create a directory named jni under sip_jni and sip_exe module, and place actual source file there. TheAndroid.mk and Application.mk (optional) are placed in the jni directory as well. Keeping files this way, we can issuendk-buildcommand right in sip_jni or sip_exe directories to compile applications.
Note that we don't create jni directory for libosip and libexosip, theirAndroid.mk is placed directly under libosipand libexosipdirectories. This is because they are dependent on by application modules. We don't need compile them directly, instead, the build system will build them automatically while building applications. In order to help build system find libosipand libexosip, we must set NDK_MODULE_PATH environment variable to the directory that directly containing libosipand libexosip. The build system will search for them based on directory name, so their names matter.

To port exosip toandroid, the essential task is to create theAndroid.mkfile, which specifies source files, c flags, ld flags, dependent libraries. We define HAVE_TIME_H and HAVE_SYS_SELECT_H to compile exosipsuccessfully. And we define ENABLE_TRACE andOSIP_MT to enable logging and multi-threading. In the last line,$(callimport-module,libosip)tells the build system that exosipdepends onosip, and all header files exported byosip(LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_C_INCLUDES)) will be included by exosipautomatically.
import-module is a feature that isn't available in the build system inandroidsource tree. It enables us organizing our projects in arbitrary manner. For example, we can place libosipand libexosipdirectories in another directory. The build system can still find them as long as NDK_MODULE_PATH is set to the directory containing them. It's much more flexible than specifying dependency relationship with relative path.

Sample:
The sample for this post is available at:
http://code.google.com/p/rxwen-blog-stuff/source/browse/trunk/android/exosip_sample/
It shows how to:

  1. use ndk build system
  2. use stl in c++ code
  3. create a very basic exosipapplication
  4. call native code from java
  5. call java code from native code

References:
ndk document
exosipuser manual

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android学习札记18:Drawable中的setDither
  2. Android的BUG(三) - 广为人知的诟病:频繁重
  3. Android: MimeType in Android
  4. Android实现弹出Toast提示
  5. Android内核和驱动篇-Android内核介绍
  6. Android中ListView以及数组适配器(ArrayA
  7. android情景模式切换的实现
  8. Android的BUG(三) - 广为人知的诟病:频繁重
  9. 直播软件源码android ui LinearLayout中
  10. eclipse android基础开发