Building Liblinphone

Here are the steps to build liblinphone on Android.

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 (at the time I'm writing this, the latest one is Android 5.1.1 - API 22)

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.

Configuring our SDK

Here 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-android-sdk', ext:'aar')
}

And now you have liblinphone sdk integrate in your project.

You can try your setup by trying to import the Core for example:
import org.linphone.Core;

How to use the SDK

There is a documentation (javadoc)  of the methods wrapped above the linphone C layer to be used in your Android application available.

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 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'`