android-notes / Cockroach

降低Android非必要crash
MIT License
3.25k stars 449 forks source link

在android 4.4.4 API 19上,点击一个按钮,触发错误。然后直接anr了 #8

Closed 411370845 closed 7 years ago

411370845 commented 7 years ago

02-27 18:54:25.200 6127-6127/com.tencent.bugly.demo E/InputEventSender: Exception dispatching finished signal. 02-27 18:54:25.200 6127-6127/com.tencent.bugly.demo E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback 02-27 18:54:25.220 6127-6127/com.tencent.bugly.demo E/MessageQueue-JNI: java.lang.RuntimeException: This Crash create for Test! You can go to Bugly see more detail! at com.tencent.bugly.crashreport.CrashReport.testJavaCrash(BUGLY:131) at com.tencent.bugly.demo.MainActivityAAA.onClick(MainActivityAAA.java:65) at android.view.View.performClick(View.java:4438) at android.view.View.onKeyUp(View.java:8244) at android.widget.TextView.onKeyUp(TextView.java:5652) at android.view.KeyEvent.dispatch(KeyEvent.java:3060) at android.view.View.dispatchKeyEvent(View.java:7668) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2143) at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1526) at android.app.Activity.dispatchKeyEvent(Activity.java:2418) at android.support.v7.internal.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:50) at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:226) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2070) at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3846) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3820) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3551) at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3712) at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2015) at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1709) at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1700) at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1992) at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:138) at android.os.Looper.loop(Looper.java:123) at com.tencent.bugly.demo.Crash$1.run(Crash.java:46) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604) at dalvik.system.NativeStart.main(Native M 02-27 18:54:25.230 6127-6162/com.tencent.bugly.demo E/CrashReport: Java Catch Happen 02-27 18:54:25.230 6127-6162/com.tencent.bugly.demo E/CrashReport: 3 02-27 18:54:25.330 6127-6162/com.tencent.bugly.demo E/CrashReport: stack frame :14, has cause true 02-27 18:54:25.600 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: #++++++++++Record By Bugly++++++++++# 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # You can use Bugly(http:\bugly.qq.com) to get more Crash Detail! 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # PKG NAME: com.tencent.bugly.demo 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # APP VER: 1.0 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # LAUNCH TIME: 2017-02-27 18:54:20 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # CRASH TYPE: JAVA_CATCH 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # CRASH TIME: 2017-02-27 18:54:25 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # CRASH PROCESS: com.tencent.bugly.demo 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # CRASH THREAD: main 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # REPORT ID: 1c91392b-82f4-4302-b75e-c5ae3e75418b 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # CRASH DEVICE: C42SD320 ROOTED 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # RUNTIME AVAIL RAM:246759424 ROM:822931456 SD:1063991296 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # RUNTIME TOTAL RAM:760266752 ROM:1044131840 SD:1069539328 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: # CRASH STACK: 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: com.tencent.bugly.demo.MyException: hahahaha this is MyException :This Crash create for Test! You can go to Bugly see more detail! at com.tencent.bugly.demo.MainActivityAAA$1$1.run(MainActivityAAA.java:50) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at com.tencent.bugly.demo.Crash$1.run(Crash.java:46) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.RuntimeException: This Crash create for Test! You can go to Bugly see more detail! at com.tencent.bugly.crashreport.CrashReport.testJavaCrash(BUGLY:131) at com.tencent.bugly.demo.MainActivityAAA.onClick(MainActivityAAA.java:65) at android.view.View.performClick(View.java:4438) at android.view.View.onKeyUp(View.java:8244) at android.widget.TextView.onKeyUp(TextView.java:5652) at android.view.KeyEvent.dispatch(KeyEvent.java:3060) at android.view.View.dispatchKeyEvent(View.java:7668) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2143) at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1526) at android.app.Activity.dispatchKeyEvent(Activity.java:2418) at android.support.v7.internal.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:50) at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:226) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2070) at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3846) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3820) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3551) at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3712) at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2015) at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1709) at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager. 02-27 18:54:25.970 6127-6162/com.tencent.bugly.demo E/CrashReport: #++++++++++++++++++++++++++++++++++++++++++# 02-27 18:54:26.180 6127-6162/com.tencent.bugly.demo E/CrashReport: not to shut down return 02-27 18:54:26.600 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:27.610 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:28.610 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:29.610 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:30.620 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:31.620 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:32.620 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:33.630 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:34.630 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:35.630 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:36.640 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:37.640 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:38.640 1556-1556/system_process E/WifiHW: get_wifi_device_num is 1 02-27 18:54:39.160 1556-1570/system_process E/ActivityManager: ANR in com.tencent.bugly.demo (com.tencent.bugly.demo/.MainActivityAAA) PID: 6127 Reason: Input dispatching timed out (Waiting because the focused window has not finished processing the input events that were previously delivered to it.) Load: 4.81 / 5.01 / 4.86 CPU usage from 5660ms to 0ms ago: 6.5% 1107/tvos: 3.1% user + 3.3% kernel 3.8% 1388/adbd: 0.5% user + 3.3% kernel / faults: 458 minor 1.7% 1556/system_server: 0.7% user + 1% kernel / faults: 129 minor 1.2% 2007/com.cantv.launcher: 1% user + 0.1% kernel 0.5% 1087/surfaceflinger: 0.5% user + 0% kernel 0.5% 5500/RtmpMlmeTask: 0% user + 0.5% kernel 0% 3574/com.tvezu.urc.service: 0% user + 0% kernel / faults: 2 minor 0% 1//init: 0% user + 0% kernel 0.1% 3/ksoftirqd/0: 0% user + 0.1% kernel 0% 1097/logwrapper: 0% user + 0% kernel 0.1% 1098/virtualkeypad: 0% user + 0.1% kernel 0.1% 1627/com.android.systemui: 0.1% user + 0% kernel 0% 1644/com.mstar.tv.service: 0% user + 0% kernel 0.1% 5498/RtmpTimerTask: 0% user + 0.1% kernel 0.1% 5599/logcat: 0% user + 0.1% kernel 0.1% 6124/kworker/0:2: 0% user + 0.1% kernel 9.4% TOTAL: 3% user + 4.4% kernel + 1.9% softirq CPU usage from 2527ms to 3046ms later: 7.6% 1107/tvos: 1.9% user + 5.7% kernel 1.9% 1449/IRQThread_202: 0% user + 1.9% kernel 1.9% 1526/Picture Monitor: 0% user + 1.9% kernel 5.7% 1388/adbd: 0% user + 5.7% kernel / faults: 48 minor 1.9% 1388/adbd: 0% user + 1.9% kernel 1.9% 5593/adbd: 0% user + 1.9% kernel 5.7% 1556/system_server: 1.9% user + 3.8% kernel 5.7% 1570/ActivityManager: 0% user + 5.7% kernel 1.9% 1585/InputReader: 1.9% user + 0% kernel 1.9% 1598/HWCursorMonitor: 1.9% user + 0% kernel 1.1% 1087/surfaceflinger: 0% user + 1.1% kernel 1.1% 1296/hwcVsyncThread: 0% user + 1.1% kernel 1.3% 2007/com.cantv.launcher: 1.3% user + 0% kernel 2.7% 2007/.cantv.launcher: 2.7% user + 0% kernel 1.4% 5599/logcat: 1.4% user + 0% kernel 1.5% 6124/kworker/0:2: 0% user + 1.5% kernel 14% TOTAL: 5.7% user + 7.6% kernel + 0.9% softirq 02-27 18:54:39.620 1087-1166/? E/SurfaceFlinger: blurlayer setlayer do not need tran! 02-27 18:54:39.620 1087-1087/? E/BlurLayer: after Layer::doTransaction

android-notes commented 7 years ago

对于anr和native crash cockroach无能为力。看了下你的异常,是不是直接复制的代码,没有使用 compile 'com.wanjian:cockroach:0.0.5' ?bugly中集成Cockroach若报资源找不到可以把app/build.gradle中 compileSdkVersion 23改成 compileSdkVersion 25就可以了。在魅族mx5 android5.1上抛出java crash打印如下


com.tencent.bugly.demo E/AndroidRuntime: --->CockroachException:Thread[main,5,main]<---
                                                                        java.lang.RuntimeException: This Crash create for Test! You can go to Bugly see more detail!
                                                                            at com.tencent.bugly.crashreport.CrashReport.testJavaCrash(BUGLY:136)
                                                                            at com.tencent.bugly.demo.MainActivity.onClick(MainActivity.java:43)
                                                                            at android.view.View.performClick(View.java:4909)
                                                                            at android.view.View$PerformClick.run(View.java:20390)
                                                                            at android.os.Handler.handleCallback(Handler.java:815)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                            at android.os.Looper.loop(Looper.java:194)
                                                                            at com.wanjian.cockroach.Cockroach$1.run(Cockroach.java:47)
                                                                            at android.os.Handler.handleCallback(Handler.java:815)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                            at android.os.Looper.loop(Looper.java:194)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5826)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at java.lang.reflect.Method.invoke(Method.java:372)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1009)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:804)

```java

并没有导致anr,app还是可以正常运行。看你的异常很奇怪,你用的什么手机,其他机型也这样吗
411370845 commented 7 years ago

我直接从demo里面拷贝过去的。。 5 i y4 otdenc ykvc_1ok

我就在button按钮测试了一个bugly的crash。结果就直接anr了。

android-notes commented 7 years ago

try{}catch中的MyException。。。。Toast代码运行在主线程中,是不是你在里面做了耗时操作。由于handlerException方法可能运行在非ui线程中, demo中又想toast弹个窗口告诉开发者有异常,所以才new 了一个handler来发送消息

411370845 commented 7 years ago

public class MyException extends Exception { public MyException() { super(); } public MyException(String detailMessage) { super(detailMessage); }

public MyException(String detailMessage, Throwable throwable) {
    super(detailMessage, throwable);
}
public MyException(Throwable throwable) {
    super(throwable);
}

} 这个类也没做啥。

public final class Cockroach {

public interface ExceptionHandler {

    void handlerException(Thread thread, Throwable throwable);
}

private Cockroach() {
}

private static ExceptionHandler sExceptionHandler;
private static Thread.UncaughtExceptionHandler sUncaughtExceptionHandler;
private static boolean sInstalled = false;//标记位,避免重复安装卸载

/**
 * 当主线程或子线程抛出异常时会调用exceptionHandler.handlerException(Thread thread, Throwable throwable)
 * <p>
 * exceptionHandler.handlerException可能运行在非UI线程中。
 * <p>
 * 若设置了Thread.setDefaultUncaughtExceptionHandler则可能无法捕获子线程异常。
 *
 * @param exceptionHandler
 */
public static synchronized void install(ExceptionHandler exceptionHandler) {
    if (sInstalled) {
        return;
    }
    sInstalled = true;
    sExceptionHandler = exceptionHandler;

    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {

            while (true) {
                try {
                    Looper.loop();
                } catch (Throwable e) {

// Binder.clearCallingIdentity(); if (e instanceof QuitCockroachException) { return; } if (sExceptionHandler != null) { sExceptionHandler.handlerException(Looper.getMainLooper().getThread(), e); } } } } });

    sUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            if (sExceptionHandler != null) {
                sExceptionHandler.handlerException(t, e);
            }
        }
    });

}

public static synchronized void uninstall() {
    if (!sInstalled) {
        return;
    }
    sInstalled = false;
    sExceptionHandler = null;
    //卸载后恢复默认的异常处理逻辑,否则主线程再次抛出异常后将导致ANR,并且无法捕获到异常位置
    Thread.setDefaultUncaughtExceptionHandler(sUncaughtExceptionHandler);
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            throw new QuitCockroachException("Quit Cockroach.....");//主线程抛出异常,迫使 while (true) {}结束
        }
    });

}
private static class QuitCockroachException extends RuntimeException {
    QuitCockroachException(String message) {
        super(message);
    }
}

}

这个是Cockroach类。全部代码都在这了。。

android-notes commented 7 years ago

CrashReport是不是一个耗时的类,注释掉看看还报不报anr

411370845 commented 7 years ago

注销Cockroach后: 不报anr了。报bugly 的 crash D/CrashReport: insert t_cr success! 02-28 11:33:12.805 10459-10598/com.tencent.bugly.demo D/CrashReport: update state size 1 02-28 11:33:12.805 10459-10459/com.tencent.bugly.demo I/CrashReport: wake up! 02-28 11:33:12.805 10459-10459/com.tencent.bugly.demo E/CrashReport: sys default last handle start! 02-28 11:33:12.815 10459-10459/com.tencent.bugly.demo E/AndroidRuntime: FATAL EXCEPTION: main Process: com.tencent.bugly.demo, PID: 10459 java.lang.RuntimeException: This Crash create for Test! You can go to Bugly see more detail! at com.tencent.bugly.crashreport.CrashReport.testJavaCrash(BUGLY:131) at com.tencent.bugly.demo.MainActivityAAA.onClick(MainActivityAAA.java:65) at android.view.View.performClick(View.java:4438) at android.view.View.onKeyUp(View.java:8244) at android.widget.TextView.onKeyUp(TextView.java:5652) at android.view.KeyEvent.dispatch(KeyEvent.java:3060) at android.view.View.dispatchKeyEvent(View.java:7668) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2143) at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1526) at android.app.Activity.dispatchKeyEvent(Activity.java:2418) at android.support.v7.internal.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:50) at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:226) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2070) at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3846) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3820) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3551) at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3712) at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2015) at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1709) at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1700) at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1992) at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:138) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604) at dalvik.system.NativeStart.main(Native Method)

411370845 commented 7 years ago

只注销掉CrashReport,代码如下 Cockroach.install(new Cockroach.ExceptionHandler() {

        // handlerException内部建议手动try{  你的异常处理逻辑  }catch(Throwable e){ } ,以防handlerException内部再次抛出异常,导致循环调用handlerException

        @Override
        public void handlerException(final Thread thread, final Throwable throwable) {
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    try {
                        throwable.printStackTrace();
                    } catch (Throwable e) {
                    }
                }
            });
        }
    });

依然会报anr

411370845 commented 7 years ago

Log 如下:

Exception dispatching finished signal. 02-28 11:39:52.945 20721-20721/com.tencent.bugly.demo E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback 02-28 11:39:52.965 20721-20721/com.tencent.bugly.demo E/MessageQueue-JNI: java.lang.RuntimeException: This Crash create for Test! You can go to Bugly see more detail! at com.tencent.bugly.crashreport.CrashReport.testJavaCrash(BUGLY:131) at com.tencent.bugly.demo.MainActivityAAA.onClick(MainActivityAAA.java:62) at android.view.View.performClick(View.java:4438) at android.view.View.onKeyUp(View.java:8244) at android.widget.TextView.onKeyUp(TextView.java:5652) at android.view.KeyEvent.dispatch(KeyEvent.java:3060) at android.view.View.dispatchKeyEvent(View.java:7668) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2143) at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1526) at android.app.Activity.dispatchKeyEvent(Activity.java:2418) at android.support.v7.internal.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:50) at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:226) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2070) at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3846) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3820) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3551) at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3712) at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2015) at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1709) at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1700) at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1992) at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:138) at android.os.Looper.loop(Looper.java:123) at com.tencent.bugly.demo.Cockroach$1.run(Cockroach.java:42) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604) at dalvik.system.NativeStart.main( 02-28 11:39:52.965 20721-20721/com.tencent.bugly.demo W/System.err: java.lang.RuntimeException: This Crash create for Test! You can go to Bugly see more detail! 02-28 11:39:52.965 20721-20721/com.tencent.bugly.demo W/System.err: at com.tencent.bugly.crashreport.CrashReport.testJavaCrash(BUGLY:131) 02-28 11:39:52.965 20721-20721/com.tencent.bugly.demo W/System.err: at com.tencent.bugly.demo.MainActivityAAA.onClick(MainActivityAAA.java:62) 02-28 11:39:52.965 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.View.performClick(View.java:4438) 02-28 11:39:52.965 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.View.onKeyUp(View.java:8244) 02-28 11:39:52.965 20721-20721/com.tencent.bugly.demo W/System.err: at android.widget.TextView.onKeyUp(TextView.java:5652) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.KeyEvent.dispatch(KeyEvent.java:3060) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.View.dispatchKeyEvent(View.java:7668) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2143) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1526) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at android.app.Activity.dispatchKeyEvent(Activity.java:2418) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at android.support.v7.internal.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:50) 02-28 11:39:52.975 20721-20721/com.tencent.bugly.demo W/System.err: at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:226) 02-28 11:39:52.985 20721-20721/com.tencent.bugly.demo W/System.err: at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2070) 02-28 11:39:52.985 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3846) 02-28 11:39:52.985 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3820) 02-28 11:39:52.985 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) 02-28 11:39:52.985 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) 02-28 11:39:52.985 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) 02-28 11:39:52.985 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518) 02-28 11:39:52.985 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) 02-28 11:39:52.995 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575) 02-28 11:39:52.995 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) 02-28 11:39:52.995 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) 02-28 11:39:52.995 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) 02-28 11:39:52.995 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) 02-28 11:39:52.995 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) 02-28 11:39:52.995 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) 02-28 11:39:52.995 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) 02-28 11:39:52.995 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3551) 02-28 11:39:52.995 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3712) 02-28 11:39:52.995 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2015) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1709) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1700) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1992) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at android.os.MessageQueue.nativePollOnce(Native Method) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at android.os.MessageQueue.next(MessageQueue.java:138) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at android.os.Looper.loop(Looper.java:123) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at com.tencent.bugly.demo.Cockroach$1.run(Cockroach.java:42) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at android.os.Handler.handleCallback(Handler.java:733) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at android.os.Looper.loop(Looper.java:136) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5001) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at java.lang.reflect.Method.invokeNative(Native Method) 02-28 11:39:53.005 20721-20721/com.tencent.bugly.demo W/System.err: at java.lang.reflect.Method.invoke(Method.java:515) 02-28 11:39:53.015 20721-20721/com.tencent.bugly.demo W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) 02-28 11:39:53.015 20721-20721/com.tencent.bugly.demo W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604) 02-28 11:39:53.015 20721-20721/com.tencent.bugly.demo W/System.err: at dalvik.system.NativeStart.main(Native Method) 02-28 11:40:00.385 20721-20764/com.tencent.bugly.demo D/CrashReport: read trace first dump for create time! 02-28 11:40:00.385 20721-20726/com.tencent.bugly.demo I/dalvikvm: threadid=3: reacting to signal 3 02-28 11:40:00.465 20721-20764/com.tencent.bugly.demo E/CrashReport: first dump error 0 0 null 02-28 11:40:00.465 20721-20764/com.tencent.bugly.demo W/CrashReport: trace dump fail could not get time! 02-28 11:40:00.475 20721-20726/com.tencent.bugly.demo I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt' 02-28 11:40:00.525 20721-20764/com.tencent.bugly.demo D/dalvikvm: GC_FOR_ALLOC freed 394K, 29% free 3340K/4660K, paused 17ms, total 18ms 02-28 11:40:00.535 20721-20764/com.tencent.bugly.demo D/CrashReport: to find! 02-28 11:40:00.535 20721-20764/com.tencent.bugly.demo D/CrashReport: waiting! 02-28 11:40:01.385 20721-20764/com.tencent.bugly.demo D/CrashReport: waiting! 02-28 11:40:01.885 20721-20764/com.tencent.bugly.demo D/CrashReport: waiting! 02-28 11:40:02.385 20721-20764/com.tencent.bugly.demo D/CrashReport: waiting! 02-28 11:40:02.885 20721-20764/com.tencent.bugly.demo D/CrashReport: waiting! 02-28 11:40:03.385 20721-20764/com.tencent.bugly.demo D/CrashReport: waiting! 02-28 11:40:03.895 20721-20764/com.tencent.bugly.demo D/CrashReport: waiting! 02-28 11:40:04.135 20721-20764/com.tencent.bugly.demo D/CrashReport: found! 02-28 11:40:04.135 20721-20764/com.tencent.bugly.demo I/CrashReport: found visiable anr , start to process! 02-28 11:40:04.145 20721-20764/com.tencent.bugly.demo D/CrashReport: anr tm:1488253200482 tr:/data/data/com.tencent.bugly.demo/files/bugly/bugly_trace_1488253200482.txt proc:com.tencent.bugly.demo sMsg:ANR Input dispatching timed out (Waiting because the focused window has not finished processing the input events that were previously delivered to it.) lMsg:ANR in com.tencent.bugly.demo (com.tencent.bugly.demo/.MainActivityAAA) PID: 20721 Reason: Input dispatching timed out (Waiting because the focused window has not finished processing the input events that were previously delivered to it.) Load: 5.29 / 5.01 / 3.55

android-notes commented 7 years ago

建议这样打印日志 Log.e("AndroidRuntime","--->CockroachException:"+thread+"<---",throwable); 控制台设置成error级别就可以了,不然会输出很多log。现在app可以正常运行吗,比如点击按钮是否有反应等

411370845 commented 7 years ago

换成: .... new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { try { Log.e("AndroidRuntime","ssss1 --->CockroachException:"+thread+"<---",throwable); // throwable.printStackTrace(); } catch (Throwable e) { } } }); .... log这样: 02-28 11:49:34.655 5706-5786/com.tencent.bugly.demo D/CrashReport: insert t_ui success! 19 02-28 11:49:35.645 5706-5706/com.tencent.bugly.demo E/InputEventSender: Exception dispatching finished signal. 02-28 11:49:35.645 5706-5706/com.tencent.bugly.demo E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback 02-28 11:49:35.665 5706-5706/com.tencent.bugly.demo E/MessageQueue-JNI: java.lang.RuntimeException: This Crash create for Test! You can go to Bugly see more detail! at com.tencent.bugly.crashreport.CrashReport.testJavaCrash(BUGLY:131) at com.tencent.bugly.demo.MainActivityAAA.onClick(MainActivityAAA.java:64) at android.view.View.performClick(View.java:4438) at android.view.View.onKeyUp(View.java:8244) at android.widget.TextView.onKeyUp(TextView.java:5652) at android.view.KeyEvent.dispatch(KeyEvent.java:3060) at android.view.View.dispatchKeyEvent(View.java:7668) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2143) at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1526) at android.app.Activity.dispatchKeyEvent(Activity.java:2418) at android.support.v7.internal.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:50) at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:226) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2070) at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3846) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3820) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3551) at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3712) at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2015) at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1709) at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1700) at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1992) at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:138) at android.os.Looper.loop(Looper.java:123) at com.tencent.bugly.demo.Cockroach$1.run(Cockroach.java:42) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604) at dalvik.system.NativeStart.main( 02-28 11:49:35.695 5706-5706/com.tencent.bugly.demo D/dalvikvm: GC_FOR_ALLOC freed 405K, 29% free 3319K/4656K, paused 13ms, total 13ms 02-28 11:49:35.705 5706-5706/com.tencent.bugly.demo E/AndroidRuntime: ssss1 --->CockroachException:Thread[main,5,main]<--- java.lang.RuntimeException: This Crash create for Test! You can go to Bugly see more detail! at com.tencent.bugly.crashreport.CrashReport.testJavaCrash(BUGLY:131) at com.tencent.bugly.demo.MainActivityAAA.onClick(MainActivityAAA.java:64) at android.view.View.performClick(View.java:4438) at android.view.View.onKeyUp(View.java:8244) at android.widget.TextView.onKeyUp(TextView.java:5652) at android.view.KeyEvent.dispatch(KeyEvent.java:3060) at android.view.View.dispatchKeyEvent(View.java:7668) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2143) at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1526) at android.app.Activity.dispatchKeyEvent(Activity.java:2418) at android.support.v7.internal.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:50) at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:226) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2070) at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3846) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3820) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3551) at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3712) at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2015) at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1709) at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1700) at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1992) at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:138) at android.os.Looper.loop(Looper.java:123) at com.tencent.bugly.demo.Cockroach$1.run(Cockroach.java:42) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) at com.android.internal.os.ZygoteInit.main(Zygot

411370845 commented 7 years ago

按钮无反应,还是会报anr

android-notes commented 7 years ago

把你工程发过来

411370845 commented 7 years ago

http://pan.baidu.com/s/1pKOnphx

android-notes commented 7 years ago

我这没问题,没有ANR,没有crash,三个按钮都可以正常点击。用的魅族mx5,android5.1,gradle 2.14-all,你的在其他手机上有没有问题

log

android-notes commented 7 years ago

arm模拟器 4.4.2也没问题 buglyarm

411370845 commented 7 years ago

我好像找到原因了。运行我给你的项目。连着USB。先用adb命令输入 adb shell input keyevent 21
这时候焦点在 “测试Java Crash” button按钮上 再输入 adb shell input keyevent 23 然后我的手机上的demo也anr了。

android-notes commented 7 years ago

这个问题确实很奇怪,不过一般情况下不会出现,并且与bugly无关,应该是adb发送键盘点击命令导致,但主线程并没有阻塞,只是没法接受触摸事件,这时再触摸屏幕就会导致ANR,若不触摸屏幕就没事,如下是测试代码,当通过adb命令发送键盘事件点击btnTestJavaCrash,并抛出异常后就会导致无法接受触摸事件,但主线程没有阻塞,可以看到延时2000ms的Toast依旧弹出了,而且也可以为btnTestJavaCrash设置文字。


@Override
    public void onClick(final View v) {
        switch (v.getId()) {
            case R.id.btnTestJavaCrash: // 点击测试Java Crash
              // CrashReport.testJavaCrash();
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ((Button) v).setText(System.currentTimeMillis()+"");
                        Toast.makeText(getApplicationContext(),"toast",1).show();
                    }
                },2000);
                if (true)
                    throw new RuntimeException("my exception--------->");
                break;
            case R.id.btnTestANRCrash: // 点击测试ANR Crash
              //  int a=3/0;
                //Toast.makeText(getBaseContext(),a,Toast.LENGTH_SHORT).show();
                break;
            case R.id.btnTestNativeCrash: // 点击测试Native Crash
             //   CrashReport.testNativeCrash();
                break;
        }
    }

cockroach

分别点击button和通过adb发送点击事件,打印日志如下

02-28 21:53:24.239 6419-6419/com.tencent.bugly.demo E/AndroidRuntime: ssss1 --->CockroachException:Thread[main,5,main]<---
                                                                      java.lang.RuntimeException: my exception--------->
                                                                          at com.tencent.bugly.demo.MainActivityAAA.onClick(MainActivityAAA.java:73)
                                                                          at android.view.View.performClick(View.java:4909)
                                                                          at android.view.View$PerformClick.run(View.java:20390)
                                                                          at android.os.Handler.handleCallback(Handler.java:815)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                          at android.os.Looper.loop(Looper.java:194)
                                                                          at com.tencent.bugly.demo.Cockroach$1.run(Cockroach.java:43)
                                                                          at android.os.Handler.handleCallback(Handler.java:815)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                          at android.os.Looper.loop(Looper.java:194)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5826)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1009)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:804)
02-28 21:53:31.724 6419-6419/com.tencent.bugly.demo E/InputEventSender: Exception dispatching finished signal.
02-28 21:53:31.724 6419-6419/com.tencent.bugly.demo E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
02-28 21:53:31.725 6419-6419/com.tencent.bugly.demo E/MessageQueue-JNI: java.lang.RuntimeException: my exception--------->
                                                                            at com.tencent.bugly.demo.MainActivityAAA.onClick(MainActivityAAA.java:73)
                                                                            at android.view.View.performClick(View.java:4909)
                                                                            at android.view.View.onKeyUp(View.java:9239)
                                                                            at android.widget.TextView.onKeyUp(TextView.java:6064)
                                                                            at android.view.KeyEvent.dispatch(KeyEvent.java:2689)
                                                                            at android.view.View.dispatchKeyEvent(View.java:8581)
                                                                            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2531)
                                                                            at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1793)
                                                                            at android.app.Activity.dispatchKeyEvent(Activity.java:2783)
                                                                            at android.support.v7.internal.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:50)
                                                                            at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:226)
                                                                            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2424)
                                                                            at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4642)
                                                                            at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4598)
                                                                            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4082)
                                                                            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4135)
                                                                            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4101)
                                                                            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4238)
                                                                            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4109)
                                                                            at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4295)
                                                                            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4082)
                                                                            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4135)
                                                                            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4101)
                                                                            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4109)
                                                                            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4082)
                                                                            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4135)
                                                                            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4101)
                                                                            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4271)
                                                                            at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4457)
                                                                            at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2359)
                                                                            at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1983)
                                                                            at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1974)
                                                                            at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2336)
                                                                            at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
                                                                            at android.os.MessageQueue.nativePollOnce(Native Method)
                                                                            at android.os.MessageQueue.next(MessageQueue.java:148)
                                                                            at android.os.Looper.loop(Looper.java:151)
                                                                            at com.tencent.bugly.demo.Cockroach$1.run(Cockroach.java:43)
                                                                            at android.os.Handler.handleCallback(Handler.java:815)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                            at android.os.Looper.loop(Looper.java:194)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5826)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at java.lang.reflect.Method.invoke(Method.java:372)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1009)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:804)
02-28 21:53:31.739 6419-6419/com.tencent.bugly.demo E/AndroidRuntime: ssss1 --->CockroachException:Thread[main,5,main]<---
                                                                      java.lang.RuntimeException: my exception--------->
                                                                          at com.tencent.bugly.demo.MainActivityAAA.onClick(MainActivityAAA.java:73)
                                                                          at android.view.View.performClick(View.java:4909)
                                                                          at android.view.View.onKeyUp(View.java:9239)
                                                                          at android.widget.TextView.onKeyUp(TextView.java:6064)
                                                                          at android.view.KeyEvent.dispatch(KeyEvent.java:2689)
                                                                          at android.view.View.dispatchKeyEvent(View.java:8581)
                                                                          at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                          at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                          at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                          at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                          at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                          at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1530)
                                                                          at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2531)
                                                                          at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1793)
                                                                          at android.app.Activity.dispatchKeyEvent(Activity.java:2783)
                                                                          at android.support.v7.internal.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:50)
                                                                          at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:226)
                                                                          at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2424)
                                                                          at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4642)
                                                                          at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4598)
                                                                          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4082)
                                                                          at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4135)
                                                                          at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4101)
                                                                          at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4238)
                                                                          at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4109)
                                                                          at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4295)
                                                                          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4082)
                                                                          at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4135)
                                                                          at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4101)
                                                                          at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4109)
                                                                          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4082)
                                                                          at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4135)
                                                                          at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4101)
                                                                          at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4271)
                                                                          at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4457)
                                                                          at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2359)
                                                                          at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1983)
                                                                          at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1974)
                                                                          at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2336)
                                                                          at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
                                                                          at android.os.MessageQueue.nativePollOnce(Native Method)
                                                                          at android.os.MessageQueue.next(MessageQueue.java:148)
                                                                          at android.os.Looper.loop(Looper.java:151)
                                                                          at com.tencent.bugly.demo.Cockroach$1.run(Cockroach.java:43)
                                                                          at android.os.Handler.handleCallback(Handler.java:815)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                          at android.os.Looper.loop(Looper.java:194)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5826)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1009)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:804)

至于深层次的原因还在研究。

411370845 commented 7 years ago

我也用模拟器试了一下,如果用模拟器的按键来操作,也会anr。智能电视的也是用遥控器的来模拟按键,操作电视,因此我才会发现这个问题。我怀疑可能是Cockroach的Looper.loop()导致anr。我看了几天也没找到解决方法,希望大神能研究出来,嘿嘿。

android-notes commented 7 years ago

很多人曲解了这个库,现在关闭这个issues