Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#2086 closed enhancement (fixed)

Add C# binding using SWIG, and support for Xamarin.

Reported by: ming Owned by: bennylp
Priority: normal Milestone: release-2.8
Component: applications Version: trunk
Keywords: Cc:
Backport to 1.x milestone: Backported: no

Description

Support C# binding using SWIG. The resulting C# binding can then be used for C# apps, as well as for Xamarin projects.

Requirements:

  1. Install swig-csharp
  2. (For C#/Xamarin development): Download Visual Studio from xamarin.com.

How to create C# binding:

  1. Go to pjsip-apps/src/swig.
  2. Run make.

To create Xamarin sample app:

  1. From Visual Studio, create new solution "Forms". Name it pjsua2xamarin in directory pjsip-apps/src/swig/csharp (we will refer this directory as [csharp_dir]).
  2. In the multiplatform section (pjsua2xamarin.pjsua2xamarin):
    • Add pjsua2 folder ([csharp_dir]/pjsua2xamarin/pjsua2xamarin/pjsua2).
    • Add sample.cs file ([csharp_dir]/pjsua2xamarin/pjsua2xamarin/sample.cs).
  3. Add code to run sample (such as in pjsua2xamarin.Droid MainActivity.cs or pjsua2xamarin.iOS AppDelegate.cs):
       pjsua2xamarin.sample test = new sample();
       test.test1();
    
  4. Add PJSIP libraries.
    • For Android: Add lib folder ([csharp_dir]/Droid/lib) and change the Build Action of libpjsua2.so to Android Native Library. For more details, please refer to the official doc.
    • For iOS: Add the fat static library file (each architecture's resulting libpjsua2.a is located in [csharp_dir]/iOS/lib/[arch]). For more info, please refer to the official doc.
  5. Set application permissions.
    See our sample apps (ipjsua for iOS and pjsua2 sample for Android) to see the typical basic permissions required.

Issues and solutions:

  • The type or namespace name 'HandleRef' does not exist.
    SWIG requires .NET 2 or later by default and uses HandleRef. Make sure you are using the supported .NET framework version.
    https://github.com/swig/swig/issues/423
    https://github.com/swig/swig/issues/455
  • TypeInitializationException, dll not found, unable to find pjsua2.
    This issue is likely caused by unsuccessful addition of the PJSIP libraries (see step 4 above), invalid path, or incorrect architecture of the libraries.
  • Crashes when calling Endpoint.libInit(), or during initialization.
    This is likely caused by unauthorized permission (see step 5 above). App must list the required permissions and in some cases, specifically request for the permissions to the user, and user must grant those permissions.

Change History (2)

comment:1 Changed 7 years ago by ming

  • Resolution set to fixed
  • Status changed from new to closed

In 5735:

Fixed #2086: Add C# binding using SWIG, and support for Xamarin

comment:2 Changed 7 years ago by ming

In 5736:

Re #2086: Add more info for better understanding of the lifetime of PJSUA2 objects. And add an example to explicitly delete PJSUA2 objects.

Note: See TracTickets for help on using tickets.