AgoraIO / RTM

143 stars 160 forks source link

Cannot initialize Agora RTM Service, error: 1 #177

Open shiv71 opened 2 years ago

shiv71 commented 2 years ago

Getting crash in Firebase crashlytics when initializing agora RTM SDK.

cannot initialize Agora RTM Service, error: 1

Fatal Exception: java.lang.RuntimeException: Unable to create application com.buddynation.dronenation.Applications: java.lang.RuntimeException: NEED TO check rtm sdk init fatal error
java.lang.IllegalArgumentException: cannot initialize Agora RTM Service, error: 1
    at io.agora.rtm.internal.RtmClientImpl.initRtmService(SourceFile:17)
    at io.agora.rtm.internal.RtmClientImpl.<init>(SourceFile:28)
    at io.agora.rtm.internal.RtmManager.createRtmInstance(SourceFile:1)
    at io.agora.rtm.RtmClient.createInstance(SourceFile:1)
    at com.buddynation.dronenation.livestream.chat.rtmtutorial.ChatManager.init(SourceFile:2)
    at com.buddynation.dronenation.Applications.onCreate(SourceFile:42)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1190)
    at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7184)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7134)
    at android.app.ActivityThread.access$1600(ActivityThread.java:274)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2102)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8167)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

       at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7189)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7134)
       at android.app.ActivityThread.access$1600(ActivityThread.java:274)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2102)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:8167)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by java.lang.RuntimeException: NEED TO check rtm sdk init fatal error
java.lang.IllegalArgumentException: cannot initialize Agora RTM Service, error: 1
    at io.agora.rtm.internal.RtmClientImpl.initRtmService(SourceFile:17)
    at io.agora.rtm.internal.RtmClientImpl.<init>(SourceFile:28)
    at io.agora.rtm.internal.RtmManager.createRtmInstance(SourceFile:1)
    at io.agora.rtm.RtmClient.createInstance(SourceFile:1)
    at com.buddynation.dronenation.livestream.chat.rtmtutorial.ChatManager.init(SourceFile:2)
    at com.buddynation.dronenation.Applications.onCreate(SourceFile:42)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1190)
    at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7184)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7134)
    at android.app.ActivityThread.access$1600(ActivityThread.java:274)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2102)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8167)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

       at com.buddynation.dronenation.livestream.chat.rtmtutorial.ChatManager.init(ChatManager.java:105)
       at com.buddynation.dronenation.Applications.onCreate(Applications.java:262)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1190)
       at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7184)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7134)
       at android.app.ActivityThread.access$1600(ActivityThread.java:274)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2102)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:8167)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
plutoless commented 2 years ago

@shiv71 hi, which demo are you running? or it's your own project? if it's your own project, could you pls share the minima reproducible project with us? cheers

shiv71 commented 2 years ago

It's our own project and we have an account on the agora and we are paid users. Our project is large and according to NDA, we can not share the project.

We are using below agora sdk implementation 'io.agora.rtc:full-sdk:3.6.0.1' implementation "io.agora.rtm:rtm-sdk:1.4.0"

I used https://github.com/AgoraIO/RTM/tree/master/Agora-RTM-Tutorial-Android for RTM code reference. I have copied the ChatManager class from the above code sample and used the same as like above sample app and sometimes throw an exception (throw new RuntimeException("NEED TO check rtm sdk init fatal error\n" + Log.getStackTraceString(e))) in the init() method in our play store app.

public void init() {
        String appID = mContext.getString(R.string.agora_app_id);

        try {
            mRtmClient = RtmClient.createInstance(mContext, appID, new RtmClientListener() {
                @Override
                public void onConnectionStateChanged(int state, int reason) {
                    for (RtmClientListener listener : mListenerList) {
                        listener.onConnectionStateChanged(state, reason);
                    }
                }

                @Override
                public void onMessageReceived(RtmMessage rtmMessage, String peerId) {
                    if (mListenerList.isEmpty()) {
                        // If currently there is no callback to handle this
                        // message, this message is unread yet. Here we also
                        // take it as an offline message.
                        mMessagePool.insertOfflineMessage(rtmMessage, peerId);
                    } else {
                        for (RtmClientListener listener : mListenerList) {
                            listener.onMessageReceived(rtmMessage, peerId);
                        }
                    }
                }

                @Override
                public void onImageMessageReceivedFromPeer(final RtmImageMessage rtmImageMessage, final String peerId) {
                    if (mListenerList.isEmpty()) {
                        // If currently there is no callback to handle this
                        // message, this message is unread yet. Here we also
                        // take it as an offline message.
                        mMessagePool.insertOfflineMessage(rtmImageMessage, peerId);
                    } else {
                        for (RtmClientListener listener : mListenerList) {
                            listener.onImageMessageReceivedFromPeer(rtmImageMessage, peerId);
                        }
                    }
                }

                @Override
                public void onFileMessageReceivedFromPeer(RtmFileMessage rtmFileMessage, String s) {

                }

                @Override
                public void onMediaUploadingProgress(RtmMediaOperationProgress rtmMediaOperationProgress, long l) {

                }

                @Override
                public void onMediaDownloadingProgress(RtmMediaOperationProgress rtmMediaOperationProgress, long l) {

                }

                @Override
                public void onTokenExpired() {

                }

                @Override
                public void onPeersOnlineStatusChanged(Map<String, Integer> status) {

                }
            });

            if (BuildConfig.DEBUG) {
                mRtmClient.setParameters("{\"rtm.log_filter\": 65535}");
            }
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
            throw new RuntimeException("NEED TO check rtm sdk init fatal error\n" + Log.getStackTraceString(e));
        }

        // Global option, mainly used to determine whether
        // to support offline messages now.
        mSendMsgOptions = new SendMessageOptions();
    }

Tell me if you want any other information.

shiv71 commented 2 years ago

@plutoless have you look this issue.

plutoless commented 2 years ago

@shiv71 sorry for late response. what params did you pass when create rtm instance? also does it work if you run our demo directly?

shiv71 commented 2 years ago

@plutoless I am passing context and agora app id. It is working fine in your demo and our app but we got two users crashing in our play store app in firebase crashlytics.

Screenshot 2022-05-09 at 11 19 55 AM Screenshot 2022-05-09 at 11 20 30 AM

plutoless commented 2 years ago

@shiv71 ok i see. so it's not constantly reproducible but only happening randomly on your online apps?

shiv71 commented 2 years ago

@plutoless Yes, you are right.