Unable to set breakpoints in Android Studio - android

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 .

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.

Required Knowledge About the debugging of android source code from android studio

I tried many times to debug my source code via breakpoint.
i am following below mention steps:
1).First, I am running my app at debug mode(Click the icon place near by run).
2).Second, Use a breakpoint in between lines of code.
3).Follow the stepin process.
But No Cursor move from this place.
please help me, I am new to learn android Native.
You need to follow the below steps to debug your app.
If you run your app in debug mode(that is by clicking the 'Debug App' icon that appears to the right of 'Run' icon), you have to set the breakpoints before you enter into the appropriate screen.
For example, if you debug your main screen of the app, you need to set the breakpoints first and then run the app in debug mode. Otherwise, you run the app in debug mode and set the breakpoints before navigating to the appropriate screen.
Simply saying setting breakpoint first is the must before running your appropriate code to debug.
The step into process allows you to get into the method code block, if any exists, in the statement attached to the breakpoint.
In order to move step by step, you must use the step over process. The step over icon appears near to the step into icon in the Debug window.

Android Studio, logcat cleans after app closes

I'm having a problem with my logcat since update 1.2 Beta for Android Studio. When I run my app it logs everything like it normally did, then I get at the point where my app crashes with the app saying: unfortunately, Game has stopped.
After a few seconds android closes that message. When that happens my logcat also gets fully cleared meaning that I barely get anytime to read the error. I did found some info about a buffer, but it seems that Android Studio doesn't have the option to increase it besides the fact that I doubt that being the problem.
Something that may be useful is that after it clears and stuff the process changes to Android.process.core and the message I get in my logcat is:
04-13 10:28:13.394 12259-12265/android.process.acore D/dalvikvm﹕
Debugger has detached; object registry had 1 entries
Edit: I did read about breakpoints, so disabled focus application on breakpoints in Settings-build, execution, deployment-debugger but it didn't have any effect.
I had the same issue, but looks more like a feature than a bug:
In AndroidStudio, the default setting for the Logcat window seems to be "Show only selected Application" (top right corner of the Logcat window)... which is looking at the log of the selected process (your current launch by default). So when your app crashes during testing, that process is gone, so the filter clears the log.
Instead, select "Edit Filter Configuration..." and set up a filter for your app, eg:
FilterName: MyApp
PackageName: com.example.myapp (<< replace with your app's package name)
...and then select that filter for future runs. This should keep the log there for you, even after the app crashes.
Switch "Show only selected application" to "No filters". This way, you can see logcat output from a process even when that process isn't running.
The downside is that your logcat will be filled with more spam from other processes.
In case of crash see the Run tab at the bottom of IDE.
You can see the crash reason in this part (even in logcat clean case).
Note: If the above trick not works try to produce a crash and immediately disconnect the mobile cable (if you use the real device for the test). you can see the error before it cleaned.
Update: If also above trick not works, try to attach and detach phone and hopefully problem solved.
Update2: If again not work, try to Invalidate catches and Restart then start debugging again.
Update3: As The last way, try to remove the app and install it again then start debugging (if you do not lose that condition you want to test)
My App was crashing and restarting. I also had some problems on reading the logcat to know what was happening. I then noticed that in the drop down menu, next to the Device dropdown it had something like "com.mypackage.myapp ('some number')" and when my app crashed there was another option that said "com.mypackage.myapp ('some number') [DEAD]". If you select the "Dead" option, it will show you the logcat of the previous instance.
Might be very late to the party but I had the same problem and solved like this:
In logcat window, top right corner drop-down menu select Edit filter configuration, on the next menu, introduce Filter name and your Package name.
Done, for me it keeps logs visible after crashing.
In Android Studio 2+
Click Run
Click Edit Configurations
In the Run/Debug Configurations window select the Miscellaneous tab
Make sure the Clear log before launch checkbox is not checked
The filter clears the log once the app gets crashed. So select "Edit Filter Configuration" and create your own custom filter with filter name. This will save the log with informations even when the app is crahed.
I'm Working with Android Studio 4.0
enter image description here
Go to Edit Configuration of your app.
Go to Miscellaneous Tab
Uncheck the field Clear log before launch.
Press OK.
It'll work..
i have faced the same issue and this is the solution :-
1- Tools --> Android --> Enable ADB Integration.
and now you can see the logcat and the crashes as normal
It is 2018 and this can still happen. Close Android Studio and reopen.
7 years later ...
I still have same issue on AS ArcticFox and nothing helps.
But I have found one workaround.
make sure this is enabled:
Then you can see your logs regardless the app is alive or not or device is connected or not. Which is great!
Still, sometimes I get this problem although some solutions work here such as restarting android studio it takes time.
Here I found how to get error message without restarting the studio
Launch the app
Be on run tab before you make your reproduce crash
Click on the content of run tab as soon as crash occurs (if you don't click on content you will lose error report)
This bug seems to be fixed with the new release of Android Studio version 1.2.2
I ran into the same problem and none of the answers could help me, until I realized my app was causing an OutOfMemoryException. That's a probable root cause as well.

How to debug android codes after loops in Eclipse

I have found my app returned error after a for loop.
Are there any tricks for me to just run through the for-loop and then debug?
I have studied some posts saying that using Ctrl+R could help.
However my latest version eclipse cannot found such a function.
You can do Step debugging in Eclipse
mark a break point in the code where you want ( mark at the blue line as shown with a small blue circle)
then run->Debug Configuration and start the app
and when the program starts it will stop at that line where you put break point.
just dont forget to change from JAva or DDMS to Debug
also you can see various stepping code things in run menu while debugging
I hope it helps you
1.use Log.i() or System.out.println() to print something.
2.just see debug information in logcat
3.reduce loop times or replace loop with other simple code, then run the app again

Why is logcat not showing anything? [duplicate]

This question already has answers here:
Why doesn't logcat show anything in my Android?
(29 answers)
Closed 7 years ago.
I am using Eclipse classic to develop my Android applications. But I am not able to see any messages in the LogCat. Till yesterday it was showing each and every message, but now it is not showing anything. I have written a lot of log statements to trace my program, but because of this I am not able to trace.
Where is the problem?
Try these first
Go to the device tab, click your device. and go back to the logcat
tab
You might have filter set.
You are probably viewing the wrong package.
I've got it solved by:
Closing the logcat window
Running the following in command prompt:
adb kill-server
adb start-server
Opening logcat again
Every now and then I experience that the logcat output in Eclipse stops showing any logs. It doesn't matter if I unplug and plug the device. It seems like the issue occurs if the logcat gets a ton of messages, and is unable to handle the amount.
The only thing working is restarting Eclipse or use DDMS directly (which also suffers from the same problem).
Go to Window - Preferences - Android - Logcat .
On that page
"Show logcat view if message priority is at least " select VERBOSE.
This happens when you don't close eclipse for a long duration, just close eclipse and reopen it, your problem should be solved.
Correct answer: it is/was a bug in Eclipse. All I did to trigger it was to rename one of the filter and pressing the Run button.
Restarting Eclipse fixes it.
In eclipse, go to: windows->preferences
Then go to Android->logcat and make sure you have the following setup:
1. double-click action: "go to problem (error line)
2. switch to: java
3. both checkboxes are checked
if your setup is fine, clean the project and restart eclipse
good luck!
Some times it does happen on a slower machine that eclipse waits for emulator HOME screen and after waiting too long it shows that the emulator is offline.
Secondly Make sure that you are looking in the correct filter or in all messages part.
Also you can do the following :
select the device and find your process (e.g. "com.android.myapp")
Look for its process id written to its left (eg. 17260)
Now go to logcat and add a new filter by witting a particular name and the specific Pid (say 17260)
Now select that filter and you'l be able to see your log messages
Good Luck!
I had the same issue, but gave up on eclipse logcat panel and switched to cygwin+adb:
make sure the app is running and launch cygwin
cd /cygdrive/c/android_sdk/sdk/platform-tools #go to where adb.exe is
[optional] ./adb logcat -c #clean the log, obviously don't do this if you want to see some old messages
./adb logcat #see all messages
or
./adb logcat | grep "whatever" #look only for whatever you want to look for
Go to Device from DDMS and open it.
Select your device from which device your application is running
Select your project which you run on this device
I had this issue for the last few days and tried everything above.
As it turned out, my problem was that all my log statements were in a class that was not being reached. I thought it had because of what was being displayed but that was not the case.
So in short, check with the following
Post log statements at the beginning of every method.
I too had the same problem , and I solved the issue by
-> restart the eclipse
-> go to ddms -> click on the emulator
I tried all the above solutions, but nothing did work. Then, I saw I had a button named "R", then something clicked in my mind, I renamed it to:
R1=(Button) findViewById(R.id.button1);
So maybe it was conflicting with R of Android and Java name of a button "R".
Hurray error got resolved.
Let us conclude with the following steps:
Check if u have any variable(button,textview) name which is “R”
Save your project, close Eclipse and then open it again.
Project --> clean
import android.R; remove this.
Correct answer: it is/was a bug in Eclipse. All I did to trigger it was to rename one of the filter and pressing the Run button. Restarting Eclipse fixes it.
You might have switched off LogCat by Mistake
Go to Preferences>Android
Click LogCat and make sure there is a check next to "Monitor logcat for messages from applications in workspace"
Then select the dropdown "Show logcat view if message priority is at least" and choose "VERBOSE" (or depending on how you tag your Logs, but VERBOSE will get all output)
Click "Apply" and you should start seeing your messages again
Make sure that you set
android:debuggable="true"
in your manifest file.
I was facing the same problem and the following steps resolved the issue:
Restart my Eclipse
Restart my Emulator
Select devices tab from DDMS perspective in Eclipse.
Check the device is not at fault. My device was set not to log, accidentally disabled it via boeffla kernel. After turning it back on logcat worked fine.
Go to windows->preference->android->logcat
select the option -
show logcat if message priority is atleat verbose.
It will show all the events of device and close all the perpestive and open logcat it will be working again.
On right top corner click on "Display Saved Filter View" or if "display saved filter view" is already open then just click on the red - icon to delete selected logcat filter.

Categories

Resources