Skip to content

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

Open
@divick

Description

@divick

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions