Using Liblinphone

Requirements

Fisrt of all, install the Android SDK from the official site. Then run the android binary and install the following:

  • Android SDK Tools
  • Android SDK Platform-tools
  • Android SDK Build-tools
  • An Android SDK platform

Please take an eye on the README and ChangeLog files from the git repo in order to make sure to have always up to date information about the project. Note that the README provide detailed instructions to compile the linphone app and liblinphone SDK, which is not required to simply use the SDK in your own app.

Create your project

Create a directory for your new project, then, create your project. You can either use the assistant from your IDE (Eclipse or Android Studio), or the command line:

android create project -n [project_name] -t [target_android_version] -p [path_to_project_dir] -k [package_name] -a [default_activity_name]

If you do create your project using the command line, you can still import it in your IDE.
For Eclipse , go to File -> Import -> Android - Existing Android Code Into Workspace.

Importing liblinphone SDK

Two options are available. The first one is to configure our maven repository in your build.gradle file and add our SDK dependency. The second one is to manually download and install our SDK.

Use our maven repository

Edit your top level gradle build file and edit the allprojects' repositories list to add our own:

maven {
    url "https://gitlab.linphone.org/BC/public/maven_repository/raw/master"
}

Then in your app's gradle build file add the either one of the following to your dependencies list:

releaseImplementation 'org.linphone:liblinphone-sdk:4.0.1'
debugImplementation 'org.linphone:liblinphone-sdk:4.0.1-DEBUG'

The 4.0.1 is the latest available version at the moment these lines are written, but feel free to use a newer one if available.

Download our SDK

You can download a zip with the latest linphone SDK for Android.

If you don't plan on doing any video, you can use a smaller SDK.

Unzip it in the root folder of your project (next to the AndroidManifest.xml file).

Your project might already contain a libs directory, in that case, just merge the two of them.

To configure your project, putting the aar in the libs/ directory should be enough.

In your build.gradle add in repositories:

repositories {
 ...
 flatDir { dirs 'libs' }
}

If for some reason it's not (for example if you decided to put the aar in another folder), just add the folder to flatDir.

And in dependencies:

repositories {
 ...
 compile(name:'liblinphone-sdk-release', ext:'aar')
}

And now you have liblinphone sdk integrated in your project.

You can try your setup by trying to start a sample Core:

System.loadLibrary("c++_shared");
System.loadLibrary("bctoolbox");
System.loadLibrary("ortp");
System.loadLibrary("mediastreamer_base");
System.loadLibrary("mediastreamer_voip");
System.loadLibrary("linphone");

Factory.instance().setDebugMode(true, "Linphone");
Core core = Factory.instance().createCore(null, null, this);
core.start();

Using liblinphone API

The cross platform reference API documentation is browsable here.

You can also download the source code of Linphone Android (see the Source Code part of this page) and take a look either at the LinphoneMini project in the sample/ folder or at the tutorials in the submodules/linphone/coreapi/help/java/org/linphone/core/tutorials/ folder.

Compile your app and run

Nothing specific to do, just compile it as a normal Android application (on Eclipse, right click on the project -> Run as -> Android Application).

Native debugging

You can natively debug Linphone-android with ndk-gdb. You must compile Linphone in debug mode:

./prepare.py -d ...

To attempt this you must had a folder in your root project nommed "JNI" with two file:

  • An empty file Android.mk
  • And Application.mk
APP_ABI := arm64-v8a x86 armeabi armeabi-v7a

On root project, run:

ndk-gdb --attach PACKAGE_NAME

When it's running you must load debug libraries (Replace PROJECT_ROOT and ABI on your convenience):

set solib-search-path PROJECT_ROOT/libs-debug/ABI/
Some devices can't run ndk-gdb like Samsung S6-S7

Troubleshooting

Activate debug traces with setDebugMode(boolean, string);

To get debug traces from adb:
adb logcat 

To get symbolicated stack trace from adb, use:
adb logcat -d | ndk-stack -sym ./libs-debug/`adb shell getprop ro.product.cpu.abi | tr -d '\r'` 

Created by SandrineAvakian on 2017/02/22 16:28