问题
My program keeps crashing, but the logcat does not show any exceptions. I just get the following message, plus a lot of stats about CPU usage. Clearly I'm using too much of the CPU, but I don't know what part of my program is doing this. Where is the following file? I can't find it.
12-30 23:13:06.639: INFO/dalvikvm(7688): Wrote stack trace to '/data/anr/traces.txt'
回答1:
adb shell
-->
cat /data/anr/traces.txt
EDIT:
You need to have root access to modify the files in /data/ you should be able to access the file with an app like https://market.android.com/details?id=com.estrongs.android.pop
Once you have that app, open it --> Menu --> Settings --> Home Directory (Change from /sdcard/
to /
) --> Exit the app --> Open it again
Then you should be able to browse to /data/anr/*
EDIT2 (Additional info, based on comments) for use with a published app after hands on testing:
Most developers rely on the developer console error reporting to see the stacktrace and error logs when a user submits an error report.
Others impliment their own or use a library like ACRA
Be warned some users do not install an app simply because it uses the permission to read sensitive log data.
回答2:
For comfortable viewing without cutted head of file use following one-line command:
adb shell "cat /data/anr/traces.txt" | less
回答3:
The ANR stands for "Android Not Responding" and it doesn't mean you're using too much of the CPU, it means that the UI main looper hadn't been called for a given amount of time. The UI looper takes care of user input, so from the point of view of your user, the app was unresponsive to input. Usually this is caused by doing long-running or blocking operations on the main UI thread. For example, downloading a file on the main thread could cause an ANR. Usually it's pretty easy to pick out the code that causes an ANR just from that information.
来源:https://stackoverflow.com/questions/8680397/how-to-find-this-stack-trace