How to debug an android application - android

Over the course of this project so far i've gotten used to looking at the logcat to tell me where the problem is when my app crashes, but my current problem doesn't crash the app it just does something it shouldn't and i can't find the code that's casuing the problem.
I've tried to debug before and go through the code line by line to see what causes it but for this android app it wont work. These are the steps i have taken.
added debuggable = true to the manifest inside the opening application tag.
added a line breakpoint on the line i wish the app to stop debugging on.
I switch to debug perspective in eclipse and start debugging the application
It seems to just stop when the console says this: Attempting to connect debugger to 'w1279057.CW1' on port 8688
Have i done something wrong?

If you are using Eclipse then http://www.vogella.de/articles/EclipseDebugging/article.html and use LogCat

If you are triying to debug on a real phone you need to enable USB debugging in the settings. It is explained here:
http://www.groovypost.com/howto/mobile/how-to-enable-usb-debugging-android-phone/

Related

Can't see the code flowing while using chrome://inspect/#devices?

I am working on an app,which I have installed in my Smartphone, I wanted to check the flow of code while running the app.
using Android Studio I installed the app via USB Debugger, and open the app project files in
chrome://inspect/#devices
, while running , I have added multiple breakpoints in the code to see the flow, but the code haven't stopped at any breakpoint, yet there is no issue with the running of app, the app ran smoothly.
I am facing the same issue while using emulator as well.
Can someone help me to figure out, what I could do ?
EDIT -
I have followed #KannanSJD instructions as well, by "Attaching Debugger to Android" and selecting "Java Only" but not got any success. , As you can see in the below attachments
make sure you attach your debugger to your app process. Use the below icon on top left
if your app package and its process is not showing then make sure you are running in Debug mode and not in release mode using build variants.
Make sure your app is open and you see your process as in screenshot.
Also instead of detect automatically you cna use Java only if you have NDK also used in your project. This will fasten the process of attaching debugger.
Also make sure you find the following log in your debug console.
Please check if you have muted your breakpoints, refer following image. That should NOT be enabled.

Unable to set breakpoints in Android Studio

I am working on Ubuntu 14.04, AndroidStudio is 1.2.1.1. I am able to build the app, click on the "Debug" icon and launch the app. I can see logcat output and I can pause the app from the debugger. The one thing I cannot do is set a break point. I tried clearing the cache, restarting AS, right clicking in the file where I want to set the break point. None of these produce the desired effect. This is a well-hidden feature.
I also had this same issue in Android Studio, where I couldn't set breakpoints. This is what I was doing wrong: I was clicking on a line that didn't have any code in it, or a line that contained a comment. As soon as I clicked on a line in method/class, it allowed me to set the breakpoint.
There shouldn't be any problems setting break points if you follow the process outlined here
If you are running into some issues, here are a few steps to get you started:
- Use a Log.d() in your app and see if it outputs to the logs. If it doesn't then you know you are not in debug mode.
- Are you debugging on the device or the emulator? If the device, you need to enable development. I would suggest to select "wait for debugger" to make sure it's attached before you run the code.
This should be pretty straightforward. Let me know what you find out.
To add a line breakpoint, proceed as follows:
Locate the line of code where you want to pause execution, then either click the left gutter along that line of code or place the caret on the line and press Control+F8 (on Mac, Command+F8).
If your app is already running, you don't need to update it to add the breakpoint—just click Attach debugger to Android proccess . Otherwise, start debugging by clicking Debug .

Application Instead of running redirects itself into Debugging mode

I have an android application,it takes me in unusual situation when I going to run my application it automatically redirects itself to debugging mode, and debugging screen is displayed whenever I want to run the application from eclipse to my cell phone,I removed all the breakpoints, I uninstalled my application, remove my project from workspace then again add it to but can't get success, I haev already tested all of the techniques which may help me to get out of this problem but nothing works for me.
Try to add below line in manifest file
android:debuggable = false
For more info visit this link

Does Android Mobile display the LogCat output or it just display what emulator displays

My question is, when we use Log.d(), Log.v(). Are these visible on android screen as output or do they just remain in the background and Android Mobile just display what the emulator displays in Computer?
Logging is just something, that enables developers the possibility to check if his code is working like it's intended to be, the user won't see any of the log statements. But it's recommended to remove all logs before publishing your App:
Turn off logging and debugging
Make sure you deactivate logging and disable the debugging option
before you build your application for release. You can deactivate
logging by removing calls to Log methods in your source files. You can
disable debugging by removing the android:debuggable attribute from
the tag in your manifest file, or by setting the
android:debuggable attribute to false in your manifest file. Also,
remove any log files or static test files that were created in your
project.
Source here.
No, this is purely a background thing, viewable with the LogCat view in Eclipse. The user will not see anything Log related, they will be oblivious to it while using the app.
So yes, it will display what your emulator displays. Of course if you need them to see something, you can show Toasts and Dialogs. However, make sure to take out Log statements in release versions of your app. People that have debugging enabled will be able to see your statements if they attach their phone to a computer and run LogCat.

How to know which line the app crashed?

I'm debugging an app in a real device and Eclipse. Certain feature makes it crash. There is no error on LogCat. I've managed to find which line it crashed in a similar situation by writting Log.v in many lines until I found which Log.v didn't show up. Isn't there a better solution?
You could use the Debugging feature in Eclipse - it allows you to break the program flow on the occurrence of an exception (Run As -> Debug).
This will allow you to inspect the current local variables / call stack to further diagnose why the exception occurs.
p.s. One other method I use when hunting down an odd crash is to dump the full LogCat via the 'adb' CLI tool, and inspect it in a text editor. Sometimes the LogCat display in Eclipse can go a bit.. weird..especially if you've been connecting / disconnecting your device while developing (without closing Eclipse)
Check Logcat filters (in Eclipse). Happens to me.
I was using the 'debug' option on Eclipse, which made it not show the error. Detaching the debug after the crash, or just running the application from the begin (without the debug options) shows the error. To find the line, filter your LogCat by application, make the app crash and, on the red text that will appear, look for your package name. And the of the error (expection) itself is on the beginning of that text.

Categories

Resources