wiki:Getting-Started/Android

Version 19 (modified by riza, 6 years ago) (diff)

--

Getting Started: Building for Android

  1. Requirements
  2. Build Preparation
  3. Building PJSIP
  4. Building and running pjsua sample application
  5. Debugging native code with Eclipse
  6. Other Android projects

Android target is currently only available in latest source code from repository, not in any release.

Requirements

Build Preparation

  1. Get the source code, if you haven't already. This tutorial applies to PJSIP version 2.2 and above (or the 2.1 from SVN trunk dated 2013/04/24 or later).
  2. Set your config_site.h to the following:
    #define PJ_CONFIG_ANDROID 1
    #include <pj/config_site_sample.h>
    
    This will activate Android specific settings in the config_site_sample.h.

Building PJSIP

Just run:

$ cd /path/to/your/pjsip/dir
$ export ANDROID_NDK_ROOT=/path_to_android_ndk_dir 
$ ./configure-android
$ make dep && make clean && make

Notes:

  • the ./configure-android is a wrapper that calls the standard ./configure script with settings suitable for Android target.
  • you may pass standard ./configure options to this script too.
  • for more info, run ./configure-android --help
  • other customizations are similar to what is explained in Building with GNU page.

Building and running pjsua sample application

We have pjsua sample application located under pjsip-apps/src/pjsua/android. It is not built by default, and you need SWIG to build it.

Follow these steps to build pjsua:

  1. Make sure SWIG is in the build environment PATH.
    • Alternatively, update SWIG path in $PJDIR/pjsip-apps/src/pjsua/android/jni/Android.mk file.
  2. Run ndk-build from directory $PJDIR/pjsip-apps/src/pjsua/android, note that the Android NDK root should be in the PATH, e.g:
    $ cd /path/to/your/pjsip/dir
    $ cd pjsip-apps/src/pjsua/android
    $ ndk-build
    
  3. Create Android project from pjsua. In Eclipse:
    1. From menu: File --> New --> Project
    2. Select Android Project from Existing Code, press Next
    3. In Root Directory, put the location of pjsua source code (i.e. $PJDIR/pjsip-apps/src/pjsua/android) and press Finish
  4. You may need to select different Android SDK than what is configured in pjsua. You can do this from the project's Properties.
  5. Run it.
  6. You will see telnet instructions on the device's screen. Telnet to this address to operate the application.

Debugging native code with Eclipse

Here are the steps for debugging PJSIP native code using Eclipse:

  1. Build PJSIP with debugging enabled, e.g: insert CFLAGS += -g into user.mak in PJSIP root directory.
  2. Make sure that the JNI part of the application is built using ndk-build. For reference, check pjsua's Android.mk build config in pjsip-apps/src/pjsua/android/jni, it contains sample of how to import PJSIP build settings (build search paths, build flags, etc) and SWIG invocation.
  3. Enable NDK plugin for Eclipse, check this and follow the instructions.
    • CDT can also be fetched from CDT download page, normally Eclipse for C/C++ will have CDT installed, just make sure that the CDT version is 7.0.2 or newer.
  4. It is recommended to introduce delay (about 5 seconds) in the application code between loading the native code library and calling any native functions (to be debugged), e.g:
    try {
    	System.loadLibrary("some_native_lib.so");
    } catch (UnsatisfiedLinkError e) {
    	return -1;
    }
    
    // Wait for GDB init
    if ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
    	try {
    		Thread.sleep(5000);
            } catch (InterruptedException e) { }
    }
    
    // Start calling native functions here
    // ...
    
  5. Load the PJSIP project to Eclipse (if not yet), and try put breakpoint anywhere in the PJSIP code before launching the Android application debug configuration in Eclipse.

Other Android projects

Also have a look at the following PJSIP Android project: