5

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.

user1680859
  • 1,160
  • 2
  • 24
  • 40

1 Answers1

2

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)

Alexey Ershov
  • 176
  • 1
  • 4
  • I already solved the problem with adding libjingle_peerconnection.jar. However it is not so clear to me why it's not giving to me the error "can not resolve symbol webrtc", when I am putting only the .jar file, without putting the .so file too. I have also found io.pristine, but I wanted to test files compiled by myself. If .jar is an JNI wrapper, what is .so file? (I am very new to webrtc). Thank you for the tutorial, very nice introduction to continue with the project. – user1680859 Dec 08 '15 at 20:09
  • @user1680859, let me explain this little further. – Alexey Ershov Dec 09 '15 at 01:43
  • 2
    @user1680859 Originally, WebRTC is written in C++, and the default Android language is Java. So, how do we use C++ from Java? The Java offers a feature called JNI (Java Native Interface), which allows you to call C++ code from Java. However, the C++ code must be properly formatted, and it's not so easy to create an "adapter" for all WebRTC C++ code by yourself, and the Java wrapper is also not that simple (see the source code). So the developers have done everything for you, and called it libjingle_peerconnection.jar and .so. (continued in next comment) – Alexey Ershov Dec 09 '15 at 01:52
  • 2
    @user1680859 the .jar file is useless without .so, as it calls C++ functions, which are compiled in the .so file (Linux .dll equivalent). I'm not sure, but you'll probably need Android NDK to make WebRTC work. You'll have to just try, or make some googling. There are plenty of materials on WebRTC. Not so many about its Android implementation, but still enough to start with. Good luck! – Alexey Ershov Dec 09 '15 at 02:03
  • the best ultra-short tutorial :), thnx @alaershov – user1680859 Dec 09 '15 at 14:45
  • @alaershov, hi... where can I download source code of libjingle_peerconnection.jar (I required 11139 the latest)? because from the URL (https://oss.sonatype.org/content/groups/public/io/pristine/libjingle/) you gave.. the source jar are all empty? I need to add method in VideoCapturerAndroid class to be able to aquire Camera object... thanks :) – Bromo Programmer Jun 01 '17 at 18:20