I've been lazy with debugging for the past couple of years with easy school projects and have just used print commands to see what was going on in my programs, but now I'm working with something more sophisticated where that just won't do, and I've found that I've forgotten how to debug.
I was getting the message "android.jar has no source attachment" when stepping into just about every other line of my code. I decided to backtrack and try to "debug" a working app of mine just to see how it works, and got the same message.
I've never used logcat before either and am not sure that I'm doing it right or what stuff means, but I typed the command "adb logcat" and a lot of text started coming up... But one line that caught my eye right around the time I stepped into a line that caused the "android.jar has no source attachment" error was: "Launch timeout has expired giving wake up lock!"
What do these things mean, and how do I fix them? These errors are coming up with a program that runs perfectly well when not debugging.
Some other possibly relevant information is that I'm using Eclipse and an Android 3.1 tablet.
Logcat is just a place where applications can log messages, just like you printed commands to check the status of your program. This link explains how to log to logcat within an application. What kind of debugging are you looking to do? If you want to see your threads, go to the DDMS perspective in Eclipse, select you device (it has to be plugged in) and process, and click update threads. You will see the running threads in the Threads view.
Also, stepping into lines in your code will try to take you to the android library's code, but you do not have the source attached. Step over the lines instead to keep debugging in your own code, not the Android library.
More info on Android debugging: http://developer.android.com/guide/developing/debugging/index.html
Related
Today I decided to update my Android Developer Tools. I am currently on version 22.3. Anyway, just after the update, logcat and eclipse have been behaving differently. As soon as I plug in the phone to the computer, logcat starts logging everything from the phone: EVERYTHING. SO as I browse some other apps and do stuff around it just keeps logging. So I see all the system calls and touch recognisers reports among all other stuff.
That is not much of a problem, it is annoying though, but once I start debugging my app it just keeps going on and on. Granted I use the session filter to only see logging related to my app. But eventually the full log increases till reaching those many entries as in the picture and eclipse starts to slow down everything. So as I am debugging my app, eclipse keeps getting slower and slower. Until our beloved beach ball kicks in and makes my life miserable once again. So far I have restarted eclipse like ten times today due to this behaviour.
This used to happen before, but as a bug, which restarting the phone or restarting eclipse used to stop. Today, nothing seems to be working. Is this now a feature? Is there any way for me to stop logcat from logging everything and only do it when I am debugging the app as it was before?
Any help is deeply appreciated.
Select specific option based your requirement
http://developer.android.com/reference/android/util/Log.html
While writing the log always try to use appropriate method as per the log type for example-
Log.d(TAG, "Message");
Log.e(TAG, "Message");
Log.v(TAG, "Message");
Log.w(TAG, "Message");
Log.i(TAG, "Message");
Then you can easily filter you log. As mentioned in answer by "shylendra" it will easy to monitor.
In Android Studio Dolphin | 2021.3.1 add package:mine in Logcat search bar. Using this filter you will see only your local app logs and errors.
See more here
I can't figure out what is going on. I am using ANdroid Studio 1.6 and I have made sure I am set to "Verbose" and I have deleted all of my filters. However when I run an application on my device, I see almost no messages. Not absolutely nothing, but maybe a dozen I/D/E level messages from dalvik and the android runtime. NOthing from my application and certainly not enough messages that I would expect from a daily driver device that has a number of apps on it with online services.
I am so confused, I've looked in every corner of the Android Studio configuration and I can't see where I might be missing something. I KNOW that it is suppressing messages because when I use my on-device logcat reader, I see everything just as expected, and it's dramatically different from what AndroidStudio is showing.
Edit: going to terminal emulator on the device and starting log cat had the same effect (messages being hidden) so this must be on the device somewhere.
Tried logcat -c and checked ANDROID_LOG TAGS
Edit2: from terminal emulator if I just type log cat then I have the aforementioned problem. If I type su logcat however then I see everything. Why would I need superuser to view the full logcat?? How would I even instruct ddms to request superuser?
I am trying to debug a simple Android application on either the emultor or a device and I cannot get the debugger to stop on any breakpoints I have set. I have combined the other posts here and throughout the web and tried all the suggestions (Add debuggable:"true" to the manifest, stop and start adb, Clean all, make sure I use the debug button not the run button, etc etc). In the Debug perspective I can see the threads and in DDMS it shows the debug icon next to the device I am debugging on. I do see the blue dots where I set the breakpoint and the Debug perspective lists them and says they are active.
I have put in alerts just before the breakpoints to verify the code is getting executed.
Starting to go crazy here. Any other suggestions? I must be missing something simple but non-obvious.
UPDATE: I appreciate the responses so far. Unfortunately they have not solved my problem. I have followed the instruction on debugging and have debugging turned on in the phone. Also, I do see the "Waiting for debugger" alert on the phone when starting. In general everything says I am debugging (including getting logcat output that I have added). It just will not stop on breakpoints that I have added and are listed in the breakpoints tab in the Debug perspective. Also just to reiterate - this happens when debugging on the device as well as on the emulator. One thing I do notice is that when I launch the debugger I have it set to bring up the Android Device Chooser. In there the "debug" column is blank for my device - but if the emulator is running the debug column does say 'Yes'. Also the console states that is attempting to connect to the debugger. Should there be a console log that states that the debugger successfully connected? I do not see this.
UPDATE 20120914: I have been away from this for some time and had given up previously. Back to try and tackle this. It is still not resolved. Everything above is still current - but one other thing I have noticed. I set a Class Load Breakpoint on the main activity and it does stop there. It just does not stop at any Line Breakpoints. I have just updated to the latest JDK 1.7.0_07, Android SDK 20, ADT Plugin 20.0.3. I have used the logcat to output a message and set a breakpoint on this line. I see the message in logcat so I know the code is being executed. The debug window in the debig perspective also does show the android application with a number of threads beneath it and the Devices window in the DDMS perspective shows the application with the green bug icon next to it.
One more thing - when the debugger is running the line breakpoints bullets do not get a checkmark overlaid on them (the Class Load Breakpoint does!). I am guessing this is the root cause - but I don't know why they are not getting this. (By the way skip breakoints is also not set - breakpoints do not have lines through them).
Any new suggestions would be appreciated. I have burned a lot of time on this. It must be something obvious that I am not seeing.
Now I feel a bit stupid writing this post. But I resolved my issue finally. The problem is you cannot set breakpoints in the Javascript code. The part I left out unintentionally is I am writing an app for Android using PhoneGap. Almost all the code is Javascript. I am so used to developing .NET web apps in Visual Studio I just assumed you could set breakpoints in the javascript code. Breakpoints in the Java code happen to work fine. Anyway, Thanks for any suggestions. Do';t know if there are other .NET developers trying PhoneGap development - but maybe this post will help them.
Android SDK provides most of the tools that you need to debug your applications. This link will introduce you to Android debugging environment and the debugging tools used.
Here's also a hands on tutorial on debugging an android application.
If you want to debug using actual android phone, turn on "USB Debugging" in your device:
Settings > Applications > Development and enable USB debugging
Android 4.0:
Settings > Developer options
AND make use of Log.d and your Logcat.
Eclipse has a debug run configuration. Only if you use the debug run configuration will a debugger be attached with the application during launch.
Does the application launch (on the device/emulator) pause a while "Waiting for Debugger" ? If not, then you are not launching the application using "debug configuration". Its the button to the immediate left of run (drop down) configuration.
Try jsHybugger: http://www.jshybugger.org/ for setting javascript breakpoints in Eclipse for remote(mobile) devices.
It lets you set breakpoints, singlestep, catch exceptions, and interact with the JS/DOM environment. You can use it from Eclipse or from a Chrome or Chrome-compatible debugger on the remote desktop. It can be used with apps that create their own webView.
However, you have to install a few files -- but probably no more complicated to use than weinre. it does extensively modify the JS files (on the fly, transparently to the user) to enable all this debugging -- webKit really should support javascript debugging natively.
Make sure you did not check skip all breakpoints (Run -> Skip all breakpoints).
Ribo already mentions it in his answer, but since this question and answers are about debugging Phonegap applications.
You certainly have to look at weinre (WEb INspector REmote).
http://people.apache.org/~pmuellr/weinre/docs/latest/
Nowadays phonegap even has it's own weinre embraced in phonegap build...
http://debug.phonegap.com/
I Am a big fan of this... (note if you are using weinre on your local machine and trying to debug a phonegap app via wifi... make sure your local device is on the same wifi network!)
I use IntelliJ IDEA to write Android apps, and use the DDMS Windows application to view the Android logs (separate from the IDE). It works fine, but after a seemingly random period of time, the logs vanish, except for one line of log, which gets overwritten with incoming logs. I have to shut it down and restart it, which combined with the delays of deploying an app to a device over ADB to debug and test is pretty tiresome.
Is this a known issue with DDMS? Is there anything I can do to make it work consistently without breaking itself?
Are there any other Android log viewing applications for Windows that work better? I'm not very fond of the IntelliJ IDEA one. My favourite is actually CatLog on Android itself, but on a small-screen device it's not a great experience.
It's not about the time, but number of lines being recorded. As Dave C said in the comment, just clear the log and it will be fine
Have you tried looking at "Why doesn't LogCat show anything in my Android?"? The top voted answer may solve your problem
Assuming I didn't start in debug mode, is there a way to make the eclipse debugger automatically start if my app throws an exception inside the emulator?
Alternatively, is there a way to get a more useful error message out of the emulator (something more useful than "Sorry, your app terminated unexpectedly").
I don't know how to trigger the debugger, but did you look at the stack trace when the error occurred, either in Eclipse DDMS (if it was already running) or using the "adb logcat" command?
https://developer.android.com/studio/debug/index.html
Yes, there is a button to add a Java exception breakpoint from the Breakpoints view in the Eclipse Debug perspective. See here for further details:
http://help.eclipse.org/galileo/topic/org.eclipse.jdt.doc.user/reference/views/breakpoints/ref-addexception_viewaction.htm
The emulator is emulating a real Android device. There is little point in displaying stack traces to an end user, hence the generic message. Use the LogCat view in the DDMS perspective.
Looks like you can almost do this in the DDMS perspective via the "Debug Process" button. It still won't break on demand if you aren't already in debug mode. And it's too late to debug if you're already looking at the "force close" dialog.