Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breakpoints not getting hit in Android Studio

I'm using Windows 7 and have recently switched from Eclipse to Android Studio. I am now having trouble debugging.

Running Android Studio 0.8.6, I set up a completely default install, I create a default empty project, targeting the ICS SDK, using the new project wizard. I then put a breakpoint in onCreate, click on the debug button and run.

The debugger attached as I can see the message "Connected to the target VM" in the debugger window.

I know the code is being executed because I am updating some text in the UI to show this.

I have tried putting breakpoints in many places but none are hit.

I'm pulling my hair out here as I just cannot see what I am doing wrong. I'm new to gradle so I think there may be some settings in gradle that I should be changing, but surely an absolutely standard project built with the wizard should let me hit breakpoints?

One thing I noticed is that in my build.gradle file there is no mention of a debug build, only a release. I wondered if that might be the problem?

buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

Note. I have tried this on both my own device and the emulator

UPDATE:

I changed the settings in the View Breakpoints options to turn on "Java Exception Breakpoints" but only for uncaught exceptions. Then, at the end of onCreate I deliberately cause a NullPointerException. When I run in debug now, I still don't hit my actual code and don't see the code break on my source, but the program does pause. I know it is my NullPointerException that is causing this because when I remove it, I can see that the code continues and does not break.

At the point that my code breaks the debug window shows that I am in the "main" thread, in a function called "performLaunchActivity". I cannot see any more information than this. Presumably therefore I am debugging through whatever level of code is calling performLaunchActivity but that my source is being treated as if I can't step through it?

like image 236
andrew Avatar asked Oct 17 '14 10:10

andrew


People also ask

Why are my breakpoints not working?

If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.

How do I activate breakpoints?

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

Can you set breakpoints in Android Studio?

The Breakpoints window lets you enable or disable each breakpoint from the list on the left. If a breakpoint is disabled, Android Studio does not pause your app when it hits that breakpoint. Select a breakpoint from the list to configure its settings.

Why are method breakpoints slow?

Method breakpoints will slow down debugger a lot because of the JVM design, they are expensive to evaluate. Remove method breakpoints and consider using the regular line breakpoints. To verify that you don't have any method breakpoints open . idea/workspace.


2 Answers

Try to remove line minifyEnabled true in file \app\build.gradle at buildTypes - debug section. Or use this screen and set Minify Enabled to false

How to enable debugging

like image 68
Pawel Cioch Avatar answered Sep 28 '22 12:09

Pawel Cioch


Make sure your JDK is latest and your system contains only one JDK.

like image 43
prettyvoid Avatar answered Sep 28 '22 12:09

prettyvoid