Skip to content

Developing Android apps

Patrik Oldsberg edited this page Apr 12, 2015 · 2 revisions

This page shows how to get started developing Android apps using OpenWebRTC and Android Studio. The process differs slightly depending on what application you are creating, but there are basically 2 different kind of apps:

  • Native - Low-level apps that use the OpenWebRTC API.
  • Hybrid - Apps that use a combination of Java code and HTML/JavaScript running in web views.

Step 1. Building OpenWebRTC

Before you can add OpenWebRTC to your Android Studio project, you need to build it.

Step 2. Adding OpenWebRTC to your project

2.1 Selecting the needed .jar files

Once OpenWebRTC has been built, you will find openwebrtc.jar and openwebrtc_bridge.jar inside cerbero/dist/android_armv7/lib/jni. openwebrtc.jar contains the base OpenWebRTC library, this is all you need if you want to create a native application. openwebrtc_bridge.jar contains the OpenWebRTC javascript bridge, which will enable you to use the WebRTC API inside Android WebViews. If you are developing a hybrid app, you will need both openwebrtc.jar and openwebrtc_bridge.jar.

2.2 Adding the libraries to your project

Copy or symlink the required .jar files to your app/libs/folder inside your Android Studio project. Then add compile files('libs/<name>') for each .jar to you dependencies block inside app/build.gradle, e.g.

dependencies {
    compile files('libs/openwebrtc.jar')
}

2.3 Adding abi filter to your android config

If you have another dependency in your project that includes libs with a different abi than OpenWebRTC is built for (armeabi), the OpenWebRTC libs might not get copied properly when your app is installed on a device. This can be solved by adding the following to the config inside the android block in app/build.gradle:

ndk {
    abiFilter "armeabi-v7a"
}

e.g.

defaultConfig {
    applicationId "com.example.owr"
    minSdkVersion 19
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"

    ndk {
        abiFilter "armeabi"
    }
}

#Step 3. Getting started with development

3.1 Remember to initialize OpenWebRTC

Before you can use OpenWebRTC in your app, it needs to be initialized. If you are creating a native application, this is done with Owr.init(), while a hybrid application is initialized with OwrBridge.start().

3.2 Example code

3.3 Documentation

Once OpenWebRTC has been built for Android, the documentation can be found in cerbero/dist/android_armv7/share/javadoc/openwebrtc