Changes between Version 71 and Version 72 of Getting-Started/Android


Ignore:
Timestamp:
Sep 27, 2017 3:15:15 AM (7 years ago)
Author:
ming
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Getting-Started/Android

    v71 v72  
    115115 
    116116For sample usage, please refer to pjsua2 sample app. Ticket #1861 explains this feature in detail. 
    117  
    118 == Setting up the target device == 
    119  
    120 To run or debug application (such as the sample applications below), first we need to setup the target device:  
    121  - using virtual device: http://developer.android.com/tools/devices/index.html 
    122  - using real device: http://developer.android.com/tools/device.html 
    123  
    124  
    125 == Building and running pjsua2 sample application == #pjsua2 
    126  
    127 A sample application using [http://www.pjsip.org/docs/book-latest/html/index.html pjsua2 API] with SWIG Java binding, is located under {{{pjsip-apps/src/swig/java/android}}}. It is not built by default, and you need [http://www.swig.org/download.html SWIG] to build it. 
    128  
    129 Follow these steps to build pjsua2 sample application: 
    130  1. Make sure SWIG is in the build environment PATH. 
    131  1. Run {{{make}}} from directory {{{$PJDIR/pjsip-apps/src/swig}}} (note that the Android NDK root should be in the PATH), e.g: 
    132      {{{ 
    133 $ cd /path/to/your/pjsip/dir 
    134 $ cd pjsip-apps/src/swig 
    135 $ make 
    136      }}} 
    137     This step should produce: 
    138     - native library {{{libpjsua2.so}}} in {{{pjsip-apps/src/swig/java/android/app/src/main/jniLibs/armeabi}}} 
    139       - note: if you are building for other target ABI, you'll need to manually move {{{libpjsua2.so}}} to the appropriate target ABI directory, e.g: {{{jniLibs/armeabi-v7a}}}, please check [https://developer.android.com/ndk/guides/abis.html#am here] for target ABI directory names. 
    140     - pjsua2 Java interface (a lot of {{{.java}}} files) in {{{pjsip-apps/src/swig/java/android/app/src/main/java/org/pjsip/pjsua2}}} 
    141  1. Make sure any library dependencies are copied to {{{pjsip-apps/src/swig/java/android/app/src/main/jniLibs/armeabi}}} (or the appropriate target ABI directory), e.g: {{{libopenh264.so}}} for video support. 
    142  1. Open pjsua2 app project in Android Studio, it is located in {{{pjsip-apps/src/swig/java/android}}}. 
    143  1. Run it. 
    144  
    145 === Log output === 
    146  
    147 The pjsua2 sample application will write log messages to '''!LogCat''' window. 
    148  
    149  
    150 == Creating your own application == #create-own-app 
    151  
    152 For developing Android application, you should use [http://www.pjsip.org/docs/book-latest/html/index.html pjsua2 API] whose Java interface available via SWIG Java binding. 
    153  
    154  1. First, build {{{pjproject}}} libraries as described above. 
    155  1. Also build {{{pjsua2 sample application}}} as described above, this step is required to generate the pjsua2 Java interface and the native library. 
    156  1. Create Android application outside the PJSIP sources for your project. 
    157  1. Get pjsua2 Java interface and native library from pjsua2 sample application: 
    158     1. Copy pjsua2 Java interface files from {{{pjsip-apps/src/swig/java/android/app/src/main/java}}} to your project's {{{app/src/main/java}}} folder, e.g: 
    159        {{{ 
    160 $ cd $YOUR_PROJECT_DIR/app/src/main/java 
    161 $ cp -r $PJSIP_DIR/pjsip-apps/src/swig/java/android/app/src/main/java . 
    162  
    163 # Cleanup excess pjsua2 application sources. 
    164 $ rm -r org/pjsip/pjsua2/app 
    165        }}} 
    166     1. Copy native library {{{libpjsua2.so}}} from {{{pjsip-apps/src/swig/java/android/app/src/main/jniLibs}}} to your project's {{{app/src/main/jniLibs}}} folder: 
    167        {{{ 
    168 $ cd $YOUR_PROJECT_DIR/app/src/main/jniLibs 
    169 $ cp -r $PJSIP_DIR/{pjsip-apps/src/swig/java/android/app/src/main/jniLibs . 
    170        }}} 
    171  1. Start writing your application, please check [http://www.pjsip.org/docs/book-latest/html/index.html pjsua2 docs] for reference. 
    172  
    173  
    174 == Pjsua application with telnet interface == #pjsua 
    175  
    176 There is also the usual [http://www.pjsip.org/pjsua.htm pjsua] with telnet command line user interface, which is located under {{{pjsip-apps/src/pjsua/android}}}. It is not built by default and you need [http://www.swig.org/download.html SWIG] to build it. Application flow and user interface are handled mainly in the native level, so it doesn't use pjsua2 API with Java interface. 
    177  
    178 Follow these steps to build pjsua: 
    179  1. Make sure SWIG is in the build environment PATH. 
    180      - Alternatively, update SWIG path in {{{$PJDIR/pjsip-apps/src/pjsua/android/jni/Makefile}}} file. 
    181  1. Run {{{make}}} from directory {{{$PJDIR/pjsip-apps/src/pjsua/android/jni}}} (note that the Android NDK root should be in the PATH), e.g: 
    182      {{{ 
    183 $ cd /path/to/your/pjsip/dir 
    184 $ cd pjsip-apps/src/pjsua/android/jni 
    185 $ make 
    186      }}} 
    187  1. Open pjsua2 app project in Android Studio, it is located in {{{pjsip-apps/src/pjsua/android}}}. 
    188  1. Run it. 
    189  1. You will see telnet instructions on the device's screen. Telnet to this address to operate the application. See [wiki:PJSUA-CLI PJSUA CLI Manual] for command reference. 
    190  
    191  
    192 {{{#!comment 
    193  
    194 == Debugging native code with Eclipse == #debug-native 
    195  
    196 Here are the steps for debugging PJSIP native code using Eclipse: 
    197  1. Build PJSIP with debugging enabled, e.g: insert {{{CFLAGS += -g}}} into {{{user.mak}}} in PJSIP root directory. 
    198  1. 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. 
    199  1. Enable NDK plugin for Eclipse, check [http://tools.android.com/recent/usingthendkplugin this] and follow the instructions. 
    200      - CDT can also be fetched from [http://www.eclipse.org/cdt/downloads.php 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. 
    201  1. 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: 
    202      {{{ 
    203 try { 
    204         System.loadLibrary("some_native_lib.so"); 
    205 } catch (UnsatisfiedLinkError e) { 
    206         return -1; 
    207 } 
    208  
    209 // Wait for GDB init 
    210 if ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { 
    211         try { 
    212                 Thread.sleep(5000); 
    213         } catch (InterruptedException e) { } 
    214 } 
    215  
    216 // Start calling native functions here 
    217 // ... 
    218      }}} 
    219  1. 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. 
    220  
    221 }}} 
    222  
    223117 
    224118== OpenSSL Support == 
     
    297191}}} 
    298192 
     193== Trying our sample application and creating your own 
     194 
     195=== Setting up the target device === 
     196 
     197To run or debug application (such as the sample applications below), first we need to setup the target device:  
     198 - using virtual device: http://developer.android.com/tools/devices/index.html 
     199 - using real device: http://developer.android.com/tools/device.html 
     200 
     201 
     202=== Building and running pjsua2 sample application === #pjsua2 
     203 
     204A sample application using [http://www.pjsip.org/docs/book-latest/html/index.html pjsua2 API] with SWIG Java binding, is located under {{{pjsip-apps/src/swig/java/android}}}. It is not built by default, and you need [http://www.swig.org/download.html SWIG] to build it. 
     205 
     206Follow these steps to build pjsua2 sample application: 
     207 1. Make sure SWIG is in the build environment PATH. 
     208 1. Run {{{make}}} from directory {{{$PJDIR/pjsip-apps/src/swig}}} (note that the Android NDK root should be in the PATH), e.g: 
     209     {{{ 
     210$ cd /path/to/your/pjsip/dir 
     211$ cd pjsip-apps/src/swig 
     212$ make 
     213     }}} 
     214    This step should produce: 
     215    - native library {{{libpjsua2.so}}} in {{{pjsip-apps/src/swig/java/android/app/src/main/jniLibs/armeabi}}} 
     216      - note: if you are building for other target ABI, you'll need to manually move {{{libpjsua2.so}}} to the appropriate target ABI directory, e.g: {{{jniLibs/armeabi-v7a}}}, please check [https://developer.android.com/ndk/guides/abis.html#am here] for target ABI directory names. 
     217    - pjsua2 Java interface (a lot of {{{.java}}} files) in {{{pjsip-apps/src/swig/java/android/app/src/main/java/org/pjsip/pjsua2}}} 
     218 1. Make sure any library dependencies are copied to {{{pjsip-apps/src/swig/java/android/app/src/main/jniLibs/armeabi}}} (or the appropriate target ABI directory), e.g: {{{libopenh264.so}}} for video support. 
     219 1. Open pjsua2 app project in Android Studio, it is located in {{{pjsip-apps/src/swig/java/android}}}. 
     220 1. Run it. 
     221 
     222==== Log output ==== 
     223 
     224The pjsua2 sample application will write log messages to '''!LogCat''' window. 
     225 
     226 
     227=== Creating your own application === #create-own-app 
     228 
     229For developing Android application, you should use [http://www.pjsip.org/docs/book-latest/html/index.html pjsua2 API] whose Java interface available via SWIG Java binding. 
     230 
     231 1. First, build {{{pjproject}}} libraries as described above. 
     232 1. Also build {{{pjsua2 sample application}}} as described above, this step is required to generate the pjsua2 Java interface and the native library. 
     233 1. Create Android application outside the PJSIP sources for your project. 
     234 1. Get pjsua2 Java interface and native library from pjsua2 sample application: 
     235    1. Copy pjsua2 Java interface files from {{{pjsip-apps/src/swig/java/android/app/src/main/java}}} to your project's {{{app/src/main/java}}} folder, e.g: 
     236       {{{ 
     237$ cd $YOUR_PROJECT_DIR/app/src/main/java 
     238$ cp -r $PJSIP_DIR/pjsip-apps/src/swig/java/android/app/src/main/java . 
     239 
     240# Cleanup excess pjsua2 application sources. 
     241$ rm -r org/pjsip/pjsua2/app 
     242       }}} 
     243    1. Copy native library {{{libpjsua2.so}}} from {{{pjsip-apps/src/swig/java/android/app/src/main/jniLibs}}} to your project's {{{app/src/main/jniLibs}}} folder: 
     244       {{{ 
     245$ cd $YOUR_PROJECT_DIR/app/src/main/jniLibs 
     246$ cp -r $PJSIP_DIR/{pjsip-apps/src/swig/java/android/app/src/main/jniLibs . 
     247       }}} 
     248 1. Start writing your application, please check [http://www.pjsip.org/docs/book-latest/html/index.html pjsua2 docs] for reference. 
     249 
     250 
     251=== Pjsua sample application with telnet interface === #pjsua 
     252 
     253There is also the usual [http://www.pjsip.org/pjsua.htm pjsua] with telnet command line user interface, which is located under {{{pjsip-apps/src/pjsua/android}}}. It is not built by default and you need [http://www.swig.org/download.html SWIG] to build it. Application flow and user interface are handled mainly in the native level, so it doesn't use pjsua2 API with Java interface. 
     254 
     255Follow these steps to build pjsua: 
     256 1. Make sure SWIG is in the build environment PATH. 
     257     - Alternatively, update SWIG path in {{{$PJDIR/pjsip-apps/src/pjsua/android/jni/Makefile}}} file. 
     258 1. Run {{{make}}} from directory {{{$PJDIR/pjsip-apps/src/pjsua/android/jni}}} (note that the Android NDK root should be in the PATH), e.g: 
     259     {{{ 
     260$ cd /path/to/your/pjsip/dir 
     261$ cd pjsip-apps/src/pjsua/android/jni 
     262$ make 
     263     }}} 
     264 1. Open pjsua2 app project in Android Studio, it is located in {{{pjsip-apps/src/pjsua/android}}}. 
     265 1. Run it. 
     266 1. You will see telnet instructions on the device's screen. Telnet to this address to operate the application. See [wiki:PJSUA-CLI PJSUA CLI Manual] for command reference. 
     267 
     268 
     269{{{#!comment 
     270 
     271== Debugging native code with Eclipse == #debug-native 
     272 
     273Here are the steps for debugging PJSIP native code using Eclipse: 
     274 1. Build PJSIP with debugging enabled, e.g: insert {{{CFLAGS += -g}}} into {{{user.mak}}} in PJSIP root directory. 
     275 1. 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. 
     276 1. Enable NDK plugin for Eclipse, check [http://tools.android.com/recent/usingthendkplugin this] and follow the instructions. 
     277     - CDT can also be fetched from [http://www.eclipse.org/cdt/downloads.php 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. 
     278 1. 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: 
     279     {{{ 
     280try { 
     281        System.loadLibrary("some_native_lib.so"); 
     282} catch (UnsatisfiedLinkError e) { 
     283        return -1; 
     284} 
     285 
     286// Wait for GDB init 
     287if ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { 
     288        try { 
     289                Thread.sleep(5000); 
     290        } catch (InterruptedException e) { } 
     291} 
     292 
     293// Start calling native functions here 
     294// ... 
     295     }}} 
     296 1. 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. 
     297 
     298}}} 
     299 
     300 
    299301== Important Issue(s) when Developing Android Apps == #issues 
    300302