I have a React Native Android app with an OpenTok view (written as a native module). I'm experiencing a crash problem (immediately upon attempt to instantiate OpenTok view) affecting older Android versions (SDK 16-19, Jelly Bean through KitKat), with any OpenTok session. More recent Android phones have no issues; OpenTok works perfectly.
Here is the relevant Android logcat output:
11-12 16:30:12.993 2949-2949/com.myapp I/OpenTokUnifiedView: APIKEY Connect Session
11-12 16:30:13.003 2949-2949/com.myapp I/OpenTokUnifiedView: apiKey: ********** sessionId: ********** token: **********
11-12 16:30:13.023 2949-2949/com.myapp I/dalvikvm: threadid=1: recursive native library load attempt (/data/app-lib/com.myapp-1/libopentok.so)
11-12 16:30:13.033 2949-2949/com.myapp I/dalvikvm: threadid=1: recursive native library load attempt (/data/app-lib/com.myapp-1/libopentok.so)
11-12 16:30:13.033 2949-2949/com.myapp I/dalvikvm: threadid=1: recursive native library load attempt (/data/app-lib/com.myapp-1/libopentok.so)
11-12 16:30:13.033 2949-2949/com.myapp I/dalvikvm: threadid=1: recursive native library load attempt (/data/app-lib/com.myapp-1/libopentok.so)
11-12 16:30:13.033 2949-2949/com.myapp I/dalvikvm: threadid=1: recursive native library load attempt (/data/app-lib/com.myapp-1/libopentok.so)
11-12 16:30:13.053 2949-2949/com.myapp E/BluetoothAdapter: Bluetooth binder is null
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: java.lang.NoClassDefFoundError: org/webrtc/voiceengine/BuildInfo
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.opentok.android.Session.init(Native Method)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.opentok.android.Session.<init>(Session.java:710)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.opentok.android.Session$Builder.build(Session.java:588)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.myapp.OpenTokUnifiedView.connectSession(OpenTokUnifiedView.java:114)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.myapp.OpenTokUnifiedView.setApiKey(OpenTokUnifiedView.java:72)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.myapp.OpenTokUnifiedViewManager.setApiKey(OpenTokUnifiedViewManager.java:34)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateViewProp(ViewManagersPropertyCache.java:83)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackViewManagerSetter.setProperty(ViewManagerPropertyUpdater.java:129)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps(ViewManagerPropertyUpdater.java:48)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.uimanager.ViewManager.updateProperties(ViewManager.java:34)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:227)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:153)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:809)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:922)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.uimanager.UIViewOperationQueue.access$2100(UIViewOperationQueue.java:47)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:982)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:31)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:136)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:107)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:759)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at android.view.Choreographer.doCallbacks(Choreographer.java:574)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at android.view.Choreographer.doFrame(Choreographer.java:543)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at android.os.Looper.loop(Looper.java:136)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at dalvik.system.NativeStart.main(Native Method)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "org.webrtc.voiceengine.BuildInfo" on path: DexPathList[[zip file "/data/app/com.myapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.myapp-1, /vendor/lib, /system/lib]]
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
11-12 16:30:13.063 2949-2949/com.myapp W/System.err: ... 34 more
11-12 16:30:13.063 2949-2949/com.myapp E/rtc: #
# Fatal error in ../../webrtc/modules/utility/source/helpers_android.cc, line 68
# last system error: 2
# Check failed: !jni->ExceptionCheck()
# Error during FindClass: org/webrtc/voiceengine/BuildInfo
#
11-12 16:30:13.063 2949-2949/com.myapp A/libc: Fatal signal 6 (SIGABRT) at 0x00000b85 (code=-6), thread 2949 (ale.app.staging)
Since it looked like org/webrtc/voiceengine/BuildInfo.class was missing, I manually added audio_device_java.jar as a library (as recommended on https://groups.google.com/forum/#!topic/discuss-webrtc/PkfAVr_TYQs ) to see if it fixed the issue.
However, it looked like OpenTok SDK already had it when I tried to build, so manually adding audio_device_java.jar did not help:
:app:transformClassesWithJarMergingForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/webrtc/voiceengine/BuildInfo.class
Not sure why the app on older Android is missing org/webrtc/voiceengine/BuildInfo.class. What could be happening on older Android?
EDIT: I found that this actually works on Lollipop -- modified this question to reflect that the issue affects up to SDK 19 (KitKat).
Finally resolved it on my own! Posting here so that others may find this useful.
I had multiDexEnabled
set to true
, so I needed to explicitly specify certain classes to keep for the older platforms to use OpenTok properly (SDK 19 and earlier).
This means that I had to include multiDexKeepProguard
in my app/build.gradle defaultConfig
:
defaultConfig {
...
multiDexEnabled true
multiDexKeepProguard file('proguard-rules.pro')
...
}
In my multiDexKeepProguard
file (mine happens to be a text file named proguard-rules.pro
in the app
directory), I had to make sure to include the following lines:
# Keep the following for OpenTok
-keep class com.opentok.** { *; }
-keep class org.webrtc.** { *; }
This allowed my OpenTok mobile app to work properly for SDK 16 (Android 4.1 Jelly Bean) through SDK 27 (Android 8.1 Oreo).