Search code examples
androidioscordovatwilioopentok

OpenTok + Twilio SDK conflicts in Android


I am developing a phonegap app for Android and iOS. I am also using Twilio and OpenTok SDK. After struggling some time I could make it both SDK to work in IOS. There was a problem with openssl libraries, because both sdk use it.

However, when testing on Android, I have linker problems. Linker is not able to find opentok.so, in presence of twilio-native.so. After removing twilio references, it all works correctly.

I have tested it on Android 4.3 and Android 5.0.

I/OTPlugin( 7998): initSession
I/OTPlugin( 7998): created new session with data: ["45149131","1_MX40NTE0OTEzMX5-MTQ0MTAyOTY2NTEyMX5xR1c2WGpJTlozNW1QODM4NjBQVlAyYUJ-UH4"]
W/dalvikvm( 7998): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/opentok/android/Session;
W/System.err( 7998): java.lang.UnsatisfiedLinkError: Couldn't load opentok from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.biotech.treatmd-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.biotech.treatmd-2, /vendor/lib, /system/lib]]]: findLibrary returned null
W/System.err( 7998): at java.lang.Runtime.loadLibrary(Runtime.java:355)
W/System.err( 7998): at java.lang.System.loadLibrary(System.java:525)
W/System.err( 7998): at com.opentok.android.Session.<clinit>(Session.java:46)
W/System.err( 7998): at com.tokbox.cordova.OpenTokAndroidPlugin.execute(OpenTokAndroidPlugin.java:394)
W/System.err( 7998): at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:84)
W/System.err( 7998): at org.apache.cordova.PluginManager.exec(PluginManager.java:151)
W/System.err( 7998): at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:63)
W/System.err( 7998): at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:40)
W/System.err( 7998): at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method)
W/System.err( 7998): at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method)
W/System.err( 7998): at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:113)
W/System.err( 7998): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 7998): at android.os.Looper.loop(Looper.java:213)
W/System.err( 7998): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:819)
W/System.err( 7998): at java.lang.Thread.run(Thread.java:841)

As you can see in the logs, loader is unable to find library. After removing twilio references, there is no problem.

 ── src
    ├── com
    │   ├── biotech
    │   │   └── treatmd
    │   │       └── MainActivity.java
    │   ├── phonegap
    │   │   └── plugins
    │   │       └── twilioclient
    │   │           ├── IncomingConnectionActivity.java
    │   │           └── TCPlugin.java
    │   ├── pushwoosh
    │   │   └── plugin
    │   │       └── pushnotifications
    │   │           └── PushNotifications.java
    │   └── tokbox
    │       └── cordova
    │           └── OpenTokAndroidPlugin.java
    └── org
        └── apache
            └── cordova
                ├── device
                │   └── Device.java
                ├── dialogs
                │   └── Notification.java
                    └── statusbar
                    └── StatusBar.java

So here is a part of the android platform folder.

├──  libs
│   ├── Pushwoosh.jar
│   ├── android-support-v4.jar
│   ├── armeabi
│   │   ├── libopentok.so
│   │   └── libtwilio-native.so
│   ├── armeabi-v7a
│   │   └── libtwilio-native.so
│   ├── mips
│   │   └── libtwilio-native.so
│   ├── opentok-android-sdk-2.3.1.jar
│   ├── twilioclient-android.jar
│   └── x86
│       ├── libopentok.so
│       └── libtwilio-native.so

Here you can see the libs folder. As I said before, when I remove twilio libs, OpenTok works perfect.

The problem I was having with iOS is that both sdk use libssl, and they are different version. The solution was delete twilio openssl library. (Even in that case, I think the only problem was that twilio brokes, not openTok, so it is weird though).


Solution

  • I have come up with the solution. Twilio cordova plugin for android is incompatible with newer version of twilio sdk. So you have to use twilio sdk version 1.2.2. Also, in order to make both plugin work together, you have to use opentok sdk version 2.5.0.