问题描述
当网络状况不好的时候,有很大概率出现ANR,日志如下:Executing service com.haoqi.truckclub/com.hyphenate.chat.EMChatServiceANR Executing service com.haoqi.truckclub/com.hyphenate.chat.EMChatService#00 pc 0002579c /system/lib/libc.so (__futex_syscall3+8)#01 pc 0000f7c4 /system/lib/libc.so#02 pc 0002df29 /data/app-lib/com.haoqi.truckclub-2/libhyphenate.so (std::recursive_mutex::lock()+2)#03 pc 00051dd1 /data/app-lib/com.haoqi.truckclub-2/libhyphenate.so#04 pc 0002ddfd /data/app-lib/com.haoqi.truckclub-2/libhyphenate.so#05 pc 0002d955 /data/app-lib/com.haoqi.truckclub-2/libhyphenate.so#06 pc 0006b58b /data/app-lib/com.haoqi.truckclub-2/libhyphenate.so (Java_com_hyphenate_chat_adapter_EMAChatClient_native_1onNetworkChanged+38)#07 pc 0001ee8c /system/lib/libdvm.so (dvmPlatformInvoke+112)#08 pc 0005038f /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+494)#09 pc 000524bb /system/lib/libdvm.so (dvmResolveNativeMethod(unsigned int const*, JValue*, Method const*, Thread*)+218)#10 pc 00028268 /system/lib/libdvm.so#11 pc 0002f70c /system/lib/libdvm.so (dvmMterpStd(Thread*)+68)#12 pc 0002cd7c /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184)#13 pc 00064783 /system/lib/libdvm.so (dvmInvokeMethod(Object*, Method const*, ArrayObject*, ArrayObject*, ClassObject*, bool)+426)#14 pc 0006cdf5 /system/lib/libdvm.so#15 pc 00028268 /system/lib/libdvm.so#16 pc 0002f70c /system/lib/libdvm.so (dvmMterpStd(Thread*)+68)#17 pc 0002cd7c /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184)#18 pc 00064279 /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+332)#19 pc 0004bc79 /system/lib/libdvm.so#20 pc 00050733 /system/lib/libandroid_runtime.so#21 pc 00051557 /system/lib/libandroid_runtime.so (android::AndroidRuntime::start(char const*, char const*)+518)#22 pc 00000ef3 /system/bin/app_process#23 pc 0000f41c /system/lib/libc.so (__libc_init+100)#24 pc 00001034 /system/bin/app_processjava:com.hyphenate.chat.adapter.EMAChatClient.native_onNetworkChanged(Native Method)com.hyphenate.chat.adapter.EMAChatClient.onNetworkChanged((null):-1)com.hyphenate.chat.EMClient.onNetworkChanged((null):-1)com.hyphenate.chat.EMSmartHeartBeat$3.onForeground((null):-1)com.hyphenate.chat.EMClient$10.onActivityResumed((null):-1)android.app.Application.dispatchActivityResumed(Application.java:208)android.app.Activity.onResume(Activity.java:1114)android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:481)com.hyphenate.easeui.ui.EaseBaseActivity.onResume(EaseBaseActivity.java:43)com.haoqi.truckclub.base.activity.BaseActivity.onResume(BaseActivity.java:45)android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1199)android.app.Activity.performResume(Activity.java:5556)android.app.ActivityThread.performResumeActivity(ActivityThread.java:2975)android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3018)android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2422)android.app.ActivityThread.access$800(ActivityThread.java:151)android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)android.os.Handler.dispatchMessage(Handler.java:110)android.os.Looper.loop(Looper.java:193)android.app.ActivityThread.main(ActivityThread.java:5351)java.lang.reflect.Method.invokeNative(Native Method)java.lang.reflect.Method.invoke(Method.java:515)com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)dalvik.system.NativeStart.main(Native Method)希望尽早修复
解决方案
建议你直接拿最新的环信版本的demo测试下的,看下还有没有这个问题,如果还复现的话 ,最好是提供下机型,还有手机中的log日志给我们的 。
解决方案二:
日志已经全部贴上去了,就是环信.so文件里面检测网络变化的时候ANR了,只要网络情况特别不好,几乎所有手机都会重现,而且这种情况实在难以模拟复现
解决方案三:
我发现问题在哪里了,在EMClient中的registerActivityLifecycleCallbacks方法中onActivityResumed调用了在接口AppStateListener中的方法onForeground,如下图: