agora-react-native-rtm icon indicating copy to clipboard operation
agora-react-native-rtm copied to clipboard

Calling join on adapter/engine before calling createClient/createInstance leads to NullPointerException

Open divick opened this issue 4 years ago • 1 comments

I am trying to integrate agora-react-native-rtm in my project which is pure ES6 and no typescript code base. I want to use agora livestream along with agora-rtm for messaging.

Based on the example in agora-react-native-rtm/example, I have created rtm-adapter which instantiates rtmEngine. But the moment I call rmtEngine.joinChannel(cid); it causes NPE.

The NPE is happening because the rtmClient instance in AgoraRTMModule.java is not created untill AgoraRTMModule::createInstance is called. From what I could gather, this is to be called from React side. But looking at the example in agora-react-native-rtm, I don't see any call to AgoraRTMModule::createInstance or AgoraRTMModule::createClient.

I tried to call createClient on rtmEngine instance, but it failed because it was unable to find the shared libs on the emulator. I copied the shared libs into android/app/src/main/jniLibs and the agora-rtm-sdj.jar into android/app/libs/ folder but now it complains of missing JNI method. Here is the stacktrace for the same.

08-23 20:04:29.358  5542  5607 E unknown:ReactNative: Exception in native call
08-23 20:04:29.358  5542  5607 E unknown:ReactNative: java.lang.RuntimeException: Could not invoke AgoraRTM.createInstance
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:383)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at android.os.Handler.handleCallback(Handler.java:883)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at android.os.Handler.dispatchMessage(Handler.java:100)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at android.os.Looper.loop(Looper.java:214)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at java.lang.Thread.run(Thread.java:919)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative: Caused by: java.lang.reflect.InvocationTargetException
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at java.lang.reflect.Method.invoke(Native Method)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   ... 8 more
08-23 20:04:29.358  5542  5607 E unknown:ReactNative: Caused by: java.lang.NoSuchMethodError: no static method "Lio/agora/rtm/jni/AgoraRtmServiceJNI;.SwigDirector_IChannelEventHandler_onImageMessageReceived(Lio/agora/rtm/jni/IChannelEventHandler;Ljava/lang/String;J)V"
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at io.agora.rtm.jni.AgoraRtmServiceJNI.swig_module_init(Native Method)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at io.agora.rtm.jni.AgoraRtmServiceJNI.<clinit>(AgoraRtmServiceJNI.java:329)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at io.agora.rtm.jni.AgoraRtmServiceJNI.new_IRtmServiceEventHandler(Native Method)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at io.agora.rtm.jni.IRtmServiceEventHandler.<init>(IRtmServiceEventHandler.java:54)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at io.agora.rtm.internal.RtmClientImpl$RtmServiceEventHandlerNative.<init>(RtmClientImpl.java:946)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at io.agora.rtm.internal.RtmClientImpl$RtmServiceEventHandlerNative.<init>(RtmClientImpl.java:946)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at io.agora.rtm.internal.RtmClientImpl.initRtmService(RtmClientImpl.java:122)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at io.agora.rtm.internal.RtmClientImpl.<init>(RtmClientImpl.java:100)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at io.agora.rtm.internal.RtmManager.createRtmInstance(RtmManager.java:20)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at io.agora.rtm.RtmClient.createInstance(RtmClient.java:63)
08-23 20:04:29.358  5542  5607 E unknown:ReactNative:   at io.agora.agora_rtm.AgoraRTMModule.createInstance(AgoraRTMModule.java:314)

I understand that right now it is in alpha/beta stage but is there a way I can make it work for the time being at least on android?

I would appreciate any help.

divick avatar Aug 23 '21 15:08 divick

is your appid correct?

LichKing-2234 avatar Aug 24 '21 03:08 LichKing-2234