Android 当应用程序崩溃并且 logcat 没有显示错误时该怎么办

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10431886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:43:41  来源:igfitidea点击:

What to do when app crashes and logcat shows no errors

androidlogcat

提问by user1301428

The app works fine in the emulator, but after installation on a phone, it crashes every time on launch, and logcat shows no errors.

该应用程序在模拟器中运行良好,但在手机上安装后,每次启动时都会崩溃,并且 logcat 没有显示任何错误。

What am I supposed to do when something like this happens?

遇到这样的事情我该怎么办?

回答by Niranjan

My Suggestion for easier resolution of your problem :

我关于更容易解决您的问题的建议:

Run the app from the eclipse in debugmode on the Phone . It will make it run on debug mode. You will most likely get more debug output.

在电话上以调试模式从 Eclipse 运行应用程序。它将使其在调试模式下运行。您很可能会获得更多调试输出。

  1. Turn on ADB in the phone.
  2. Connect the Phone to the PC
  3. Run as "Debug Configuration" from eclipse.
  4. It should run from your phone and Eclipse will ask for your choice for first time before running that.
  1. 在手机中打开 ADB。
  2. 将手机连接到电脑
  3. 从 Eclipse 中作为“调试配置”运行。
  4. 它应该在你的手机上运行,​​Eclipse 会在运行之前第一次询问你的选择。


Turning the Debug Modeon ( Note : This isn'tthe 'ADB connection' we are referring to ) , It will enable further logging of the application and doesn't do garbage collection normally.

打开调试模式(注意:这不是我们所指的“ADB 连接”),它将启用应用程序的进一步日志记录,并且不会正常进行垃圾收集。

( You will notice a 'Waiting for debug connection'dialogue , if the applications are forced to work in debug mode ).

(如果应用程序被迫在调试模式下工作,您会注意到“等待调试连接”对话框)。

For e.g :It makes the Async threads keep running and doesn't stop running. Crude and irrelevant for your case . But just as an example.

例如:它使异步线程继续运行并且不会停止运行。粗鲁且与您的情况无关。但只是作为一个例子。

So , Since the Applications in the phone are forcedto run in debug mode , it will get the logcat with detailed errors down to the specific threads.

因此,由于手机中的应用程序被迫在调试模式下运行,因此它将获取包含详细错误的 logcat 到特定线程。

However, the debug mode is better usedwhen it's used in conjunction with "Debug As" run configurationfrom Eclipse. And keep in mind that it will automaticallyturn on that debug application mode ( And there by the dialog box also) , the logcat will show you more details and plus it will break-pointat the errors which occur ,in their sequence of occurence.

但是,当调试模式与来自 Eclipse 的“Debug As”运行配置结合使用时,它的使用效果会更好。请记住,它会自动打开该调试应用程序模式(还有对话框),logcat 将向您显示更多详细信息,并且它在发生的错误处断点,按照它们的发生顺序。



Regarding what Ares told,When you want to do the debugging of a process directly,

关于Ares所说的,当你想直接做一个进程的调试时,

  1. You can go to the DDMS panel in Eclipse,
  2. On the right side tab menu Devices,
  3. Select the process you want to debug . and click on the green symbol ( Says, Start Debugging process )
  4. It will automatically go to the source when it breaks if you have the source code in that eclipse work-space.
  1. 您可以转到 Eclipse 中的 DDMS 面板,
  2. 在右侧选项卡菜单Devices
  3. 选择要调试的进程。然后单击绿色符号(说,开始调试过程)
  4. 如果您在该 eclipse 工作空间中有源代码,它会在中断时自动转到源代码。

回答by Adreamus

Additional hint:

补充提示:

On huawei phones, logcat doesn't show debug messages and excpetions, if the phone is in default system settings.

在华为手机上,如果手机处于默认系统设置,logcat 不会显示调试消息和异常。

In order to enable logcat full logs on Huawei phones, you must do the following:

为了在华为手机上启用logcat full日志,您必须执行以下操作:

  • Open the factory settings menu by dialing *#*#2846579#*#*
  • Navigate to Project Menu / Background Setting / Log setting

  • On older phones: define the log availability (log switch) and level (log level setting).

  • On never phones: tick AP Log (which seems to enable app logging in general) and CP Log (seems to enable debug logging)
  • Close the menu with your backbutton (no restart needed)
  • 通过拨号打开出厂设置菜单 *#*#2846579#*#*
  • 导航到项目菜单/背景设置/日志设置

  • 在旧手机上:定义日志可用性(日志切换)和级别(日志级别设置)。

  • 在 never 手机上:勾选 AP Log(似乎通常启用应用程序日志记录)和 CP Log(似乎启用调试日志记录)
  • 使用后退按钮关闭菜单(无需重新启动)

Source: https://stackoverflow.com/a/18395092/1075072

来源:https: //stackoverflow.com/a/18395092/1075072

回答by Heiko Rupp

Install a tool like AndroidSystemInfothat can show you the logfile on the phone - even when you are away from the host computer.

安装一个像AndroidSystemInfo这样的工具,它可以在手机上向你显示日志文件——即使你远离主机。

It is pretty unusual that Android leaves no trace whatsoever.

Android 没有留下任何痕迹是很不寻常的。

Does your app perhaps require features that the phone does not have (e.g. a camera or gps or nfc)?

您的应用程序是否可能需要手机没有的功能(例如相机、gps 或 nfc)?

回答by Nolesh

In Eclipse you should go to DDMS, then click on device's name or android.os in Devicespanel. And turn your device in debug mode.

在 Eclipse 中,您应该转到 DDMS,然后在Devices面板中单击设备名称或 android.os 。并将您的设备置于调试模式。

回答by AmDroid

  1. You can reset adb (In Devices -> View menu -> Reset adb)
  2. Click on the selected online device/emulator to show the logcat
  3. Disconnect the cable and again connect it. (Or restart the emulator)
  4. Restart Eclipse
  1. 您可以重置 adb(在设备 -> 查看菜单 -> 重置 adb)
  2. 点击选中的在线设备/模拟器显示logcat
  3. 断开电缆并重新连接。(或者重启模拟器)
  4. 重启 Eclipse

回答by Bruno Carrier

I restarted my emulator and cleaned my build. This got rid of both the non-logging and the spurious crash I was having

我重新启动了我的模拟器并清理了我的构建。这摆脱了我遇到的非日志记录和虚假崩溃

回答by Dmytro Danylyk

Put your own logs to track what block of code cause crashe, or just debug it.

放置您自己的日志以跟踪导致崩溃的代码块,或者只是调试它。