Search code examples
androidandroid-studiojava-native-interfacewebrtcapprtcdemo

Cannot resolve symbol webrtc in Android Studio


I am trying to use webrtc in Android Studio. The file libjingle_peerconnection_so.so is put int the folder src/main/jniLibs/arneabi-v7a. But when I put in a Java file:

import org.webrtc.DataChannel;

it tells me that can not resolve "Cannot resolve symbol webrtc". Any help appreciated.


Solution

  • First, its armeabi-v7a, not arneabi-v7a, but that alone will not solve your problem :)

    You are going the hard way, so here is a little theory:

    The file libjingle_peerconnection_so.so itself is not enough to use WebRTC in Java program. At least, you need the Java JNI wrapper for WebRTC core, which provides you all necessary Java classes to work with native WebRTC code. Default wrapper is usually libjingle_peerconnection.jar, which you should put in "libs" folder on the same level as your "src" folder. So, your project tree should have these files:

    • src/main/jniLibs/armeabi-v7a
    • libs/libjingle_peerconnection.jar

    Also you need to tell your build system to build the .jar in your app. In Android Studio it's usually Gradle, so just add compile files('libs/libjingle_peerconnection.jar') into your dependencies.

    But there is also the easy way! Good guys from pristine.io regularly build WebRTC for Android and publish some pre-built versions to Maven repository (see here). So, you can just add compile 'io.pristine:libjingle:10839@aar' to your Gradle dependencies, and go. No need to add .so files and all that. Here is their article on that (note the outdated WebRTC version, you can use 10839, for example)