Xamarin SDK

To use Linphone with Xamarin, you need the SDK which embeds and wraps the native libraries for Android & iOS  (for each architecture) to develop cross-platform mobile applications in C#.

Adding the NuGet package to your project (>= 5.2.0)

Since version 5.2.0, a .nupkg is availble for download from our self-hosted NuGet package registry.

  1. Add the Linphone package source to your development environment (You only need to do that once)
    nuget source Add -Name "Linphone" -Source "https://gitlab.linphone.org/api/v4/projects/411/packages/nuget/index.json"
    Or in Visual Studio, go to Tools->Nuget Package Manager->Package Manager Settings, then Package sources, and add a new package source with the URL above.
  2. Install the LinphoneSDK package from that new source
    nuget install LinphoneSDK -Source "Linphone"

You will then be able to update the package as you do other NuGet packages, and are now ready to start developing cross-platform mobile SIP apps with Xamarin or Maui. Although it is not leveraging this new nuget package yet, we recommend taking a look at our sample app to get you started.

What's in the box

The SDK embeds the following:

  • The Android libraries for armv7, arm64 (as AAR) ;
  • The iOS libraries for armv7, arm64 and x86_64 (as frameworks) ;

If you want to support an architecture that is not included in our SDK (for example x86), you can compile the libraries by yourself (see below).

Manually wrapping the native libraries from within your project (< 5.2.0)

To use any version of the Linphone SDK before 5.2.0, you will have to add boiler-plate wrapper projects to your solution. The process of which is described below.

You can build your own native libraries (see Linphone SDK README file) or you can download a pre-built ZIP archive with the native libraries for both Android & iOS plus the C# wrapper.

Pre-built SDK are available at in two flavors: releases or nightly builds. Nightly builds are built every night from the master branch of linphone-sdk instead of release branch.

Architecture

Once you have our SDK (either built by yourself or a pre-built archive you downloaded), you can open the Xamarin.sln solution inside the Xamarin folder of our sample app.

The sample we provide is a solution using four projects: one for Android, one for iOS, and two shared: one for the native libraries (our SDK), one for the app itself (the shared part).

The Android project contains the Android Manifest for the generated APK and an Activity that will load and display the application from the shared project.

The iOS project does the same thing that the Android one, but for iOS (obviously).

Set-up the SDK

Android

If you haven't done it already, also copy the C# wrapper in linphone-sdk-ios\linphone-sdk\apple-darwin\share\linphonecs\LinphoneWrapper.cs into Xamarin\Xamarin\Xamarin\LinphoneWrapper.cs (the name must remain the same).

For the C# wrapper to work, it needs to find the Linphone native libraries. Here's the procedure to add them to the project:

Copy the AAR with the native libraries (either the debug or the release one) into Xamarin\Xamarin\Liblinphone\liblinphone-sdk.aar (the name must remain the same).

iOS

If you haven't done it already, also copy the C# wrapper in linphone-sdk-ios\linphone-sdk\apple-darwin\share\linphonecs\LinphoneWrapper.cs into Xamarin\Xamarin\Xamarin\LinphoneWrapper.cs (the name must remain the same).

For the C# wrapper to work, it needs to find the Linphone native libraries. Here's the procedure to add them to the project:

  • Import the Frameworks folder with all the frameworks within your Xamarin.iOS project ;
  • Right click on your Xamarin.iOS project then select add -> add native references and select all the frameworks you imported in the project.

Do not forget to add your required permissions in your project Info.plist (i.e: use of microphone etc...) or your app will crash !

Platform specifics

Android

Don't forget to add the required permissions to the AndroidManifest.xml file. Here's the list of all permissions our SDK might need:

<uses-permission android:name="android.permission.RECORD_AUDIO" ></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" ></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK" ></uses-permission>
<!-- Needed to be able to use WifiManager.MulticastLock -->
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" ></uses-permission>
<uses-permission android:name="android.permission.CAMERA" ></uses-permission>
<!-- Needed to allow Linphone to install on tablets, since android.permission.CAMERA implies android.hardware.camera and android.hardware.camera.autofocus are required -->
<uses-feature android:name="android.hardware.camera" android:required="false" ></uses-feature>

Finally if you are deploying on Android >= 23 ask at runtime the permissions like you would do on a native Android application.

iOS

Troubleshooting

If you encounter the following issue (or similar):

Org.Linphone.Core.ICoreListener.cs(35,35): Error CS0102: The type 'TransferStateChangedEventArgs' already contains a definition for 'p0' (CS0102) (Liblinphone)

Org.Linphone.Core.ICoreListener.cs(35,35): Error CS0102: The type 'IsComposingReceivedEventArgs' already contains a definition for 'p0' (CS0102) (Liblinphone)

Org.Linphone.Core.ICoreListener.cs(35,35): Error CS0102: The type 'MessageReceivedEventArgs' already contains a definition for 'p0' (CS0102) (Liblinphone)

Org.Linphone.Core.IConferenceListener.cs(41,41): Error CS0102: The type 'ParticipantAddedEventArgs' already contains a definition for 'p0' (CS0102) (Liblinphone)

Make sure the Transforms/Metadata.xml file of your project contains the following:
<remove-node path="/api/package[@name='org.linphone.core']" ></remove-node>