Android studio doesn't catch breakpoint after switching to other apps - android

I have a problem debugging the app in Android Studio 1.4.
A typical debug aspect is when, debugging on a physical device, I purposedly switch to other
apps and then I come back to my app to check if the current Activity has some
"null" variables that prevent activity from properly recharging.
I usually set some breakpoint at the beginning of the (onResume) method.
The problem is: when I run the app the first time, the breakpoint is normally taken.
When I switch to other apps and then return to the debugging app,
Android Studio doesn't catch the breakpoint, so I cannot debug what's wrong.
The same thing seemed to work properly in Eclipse.
Do you have any idea how to solve this? Thanks.

if your process is killed then the debugger is no longer attached.
You can attach a new debugger at any point
do this just after you finish using the last app and before you open your app
It will give you a list of processes and you have to select which process to attach the debugger to.
Usually the process name includes a prefix of your package name.
https://blog.pivotal.io/labs/labs/fast-android-debugging-with-intellij

Related

Android application lacking debug information in Android Studio

I'm trying to debug an application that I'm writing using Android Studio but I can't seem to get any useful debugging information out of Android Studio's "Debug" view. I'm launching my application with the bug-looking "Debug" icon but the "Debug" view doesn't have anything useful (no stack frames from my application, for example):
Even if my application crashes I don't get any useful information. As I recall, the ADT plugin would automatically drop you on the line that caused the crash.
Do I need to do anything else to make my application "debuggable" in Android Studio? I've also tried forcing android:debuggable="true" in my AndroidManifest.xml but to no avail. Android Studio does seem to be attaching to the running process (the app shows the "attaching to debugger" message for a few seconds when it first launches).
There are some things to check:
If your app-debugger is working and stopping on normal breakpoints, maybe you have to set an exception-breakpoint:
Open Debugger
Press "View breakpoints"
Usually, there should be a breakpoint called "Any exception" with checkboxes on "Caught exception" and "Unchaught exception". If not, add an exception breakpoint yourself and specify the type(s) of exceptions you want the debugger to stop on (you can use wildcards in the exception-classnames, e.g. *Exception).
If your app-debugger is not working, check the following options:
Check if you have enabled USB-Debugging in the developer options of your device
Check if you have authorized the computer as a development machine in the developer options of the device (if unsure, clear the authorization-list from the developer options page and reconnect the device)
Check if your development machine has only one adb-server-process running in the background (if more, kill all of them with a process mananger and restart with "adb start-server")
Add "debuggable true" to your debug-buildType in build.gradle:
buildTypes {
debug {
debuggable true
}
...
}
If your app-debugger is still not working, restart your computer and re-install adb-drivers for your device. Make sure there are no conflicting drivers active with more than one connected device (maybe connecting only one at a time).
Note: even if you got exception breakpoints working, they might not be useful at all, depending on the type of the crash. Most of the times, you will get the debugger stopping in the Zygote-exception handler where you don't get much useful information or stacktrace.
In such cases, it is the easiest to just let the debugger resume or reproduce the crash without a debugger, and check the logcat-output for a stacktrace in the ERROR-loglevel of your app's logcat-output. Those stacktraces should have clickable line-infos thus enabling you to set a normal breakpoint on a relevant line of code in your app's source code to analyze the problem.
After updating Android studio this problem went away. Not sure what the issue was.

LogCat is not showing null pointer exception

My LogCat is often not showing null pointer exceptions..
Sample:
ProgressDialog pd;
ps.show();
Application stops (do not reacts for any action), but there is no information about any reason in logcat.
Another sample is with database - if there is no DB and I'm making actions on it, the same happens.
I tried (that action with DB) on my colleague's phone and there was normal error. I have all needed programmer options in my phone turned on.
Maybe someone know , why it is so? It was not burdensome, when I had small app, but now when it's bigger, it can be really frustrating.
I get this with android studio too...
Close android studio, restart ADB, and generally it starts working for me.
If that does not work then put a breakpoint at the line .show(); ... Then open up the logcat and then skip over the breakpoint. It then shows, I have similar issues.
(Windows 7 64 bit - Android Studio 0.82)
I dont like the IDE logcat option honestly.
The SDK comes with an adb binary, use the logcat option from there via
adb logcat or my personal favorite built in alias, adb lolcat
This will give you the log information for EVERYTHING happening on the device, and can be useful tracking down issues caused by device state.
For example, you can see network changes in the logcat, and if your app crashes on network call you wouldnt have any idea why if you just used the logcat output from your app.
In my case I was using: Thread.setDefaultUncaughtExceptionHandler in my application file. If that is not turned off during debugging you won't see any exception output. ( Just make sure to turn it back on again when you release so you can still handle your issues ).

Debugger has detached: object registy had 1 entry. Android Logcat Message

My Android apps are running ,but can't view anything on logcat view. When I start eclipse,I get this message
Debugger has detached: object registy had 1 entry.
What does this message mean? It wasn't happening before,until yesterday where I wrote a new app. I don't think that my code is wrong,but the debugger has detached for some reason.
When DDMS attaches, it uses the same connection as a debugger. When it disconnects, you get that message. Had an actual debugger been attached, the object registry would have more than one entry in it.
Try this: with the DDMS view active in Eclipse, disconnect USB, then reconnect it. If you scroll back in logcat you should see that, when the USB connection dropped, a "debugger has detached" message was emitted by every debuggable app that was running.
Apps are only debuggable if they have the android:debuggable flag set in their manifest, or you're on a developer ("userdebug") device (which has the system property ro.debuggable set to 1). If you're on a production device, you'll generally only see the "detached" message for apps you're developing that happen to be running.
You can safely ignore the message.
You should take off all breakpoints that you put in your code.
In Eclipse:
Window->Show View->(Other->Debug->)Breakpoints. Hope this helps you.
UPDATE:
In Android Studio (see marks on attached screenshot) you can choose which breakpoints would you like to remove by hitting upper button or just disable all existing breakpoints by hitting lower button.

Android: How should I respond to "Hot Code Replace Failed" dialog in Eclipse?

When my Android application is already running and I change the code I get the "Hot Code Replace Failed" dialog.
I'm wondering what the correct response is (terminate or disconnect) if I want Eclipse to update my code on the device when I encounter it.
What is the difference between terminate and disconnect?
Also, I'm wondering if I click the "Do not show error when hot code replace is not supported", what will Eclipse do in the future when this scenario occurs?
Depending on the VM used (Dalvik in this case), some code changes can be made whilst debugging that will 'hot deploy' or 'hot replace'. This means that the code changes will immediately take effect on the emulator and you can test them without the need to re-deploy your app. This sort of hot re-deployment is more commonly used when working with enterprise applications that may take 10 minutes to build and deploy and so wastes a lot of time during development.
The HotSpot VM (the VM usually used on PCs) allows only simple code replacement and fails if you try to add/rename a field member or method. I'm not sure what sort of support the Dalvik VM provides but if you make a change it does not support you'll get that dialog box.
Now, as for the buttons:
Continue: Accept that the changes you have made will not take effect immediately in the emulator and continue debugging
Terminate: Kill the app
Disconnect: Do not kill the app but end the debugging session (i.e. disconnect the debugger)
If you check the box, it will always Continue.
I'm wondering what the correct response is (terminate or disconnect) if I want Eclipse to update my code on the device when I encounter it.
There's no direct way to have Eclipse update your running code on the emulator when you encounter this dialog as the Dalvik VM does not suppot hot swap, i.e. the update of running code. You'll have to redeploy the app to your emulator manually.
What is the difference between terminate and disconnect?
Terminate will terminate the app being debugged on the emulator/device.
Disconnect will just disconnect the debugger, and leave the app running on the emulator/device.
Also, I'm wondering if I click the "Do not show error when hot code replace is not supported", what will Eclipse do in the future when this scenario occurs?
It "won't show error when hot code replace is not supported" obviously ;) -- i.e. it won't warn you and any changes you do will not be hot-swapped into the running app (because the Dalvik VM doesn't support hot-swapping like Oracle's JVM for example).
I usually Terminate and then re-publish my application with the changed code.

Debugging not working in a service class ?? what can cause this issue?

All of a sudden I am not able to debug anything that i am doing in a service even though i put breakpoints all over. but logging shows that all the lines are getting executed. Can someone tell me what could be causing this issue. I am using eclipse and i have set to "Build automatically".
Do you have an Activity which is launched at the beginning of your application?
If not you have to manually activate the debug on your process by using the DDMS tool in Eclipse.
In DDMS -> Devices, check your process (the line contains the package name of your app), select it and then click on the debug button. A debug icon will appear near your process, then you should be able to use breakpoints in your Service.
If you are using a Runnable try placing this in the run() method:
android.os.Debug.waitForDebugger();

Categories

Resources