Breakpoints not getting hit in Android Studio

15,029

Solution 1

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

Solution 2

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

Share:
15,029
andrew
Author by

andrew

Updated on June 06, 2022

Comments

  • andrew
    andrew almost 2 years

    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?

  • andrew
    andrew over 9 years
    Yep. The breakpoint appears fine. I'm setting it by clicking in the "gutter", or with ctrl f8. If I do run -> view breakpoints, I can se that it is there and is set to suspend all
  • vkm
    vkm over 9 years
  • andrew
    andrew over 9 years
    Yeah. I have tried but still nothing, apart from that it flags a warning telling me I shouldn't explicitly define this.
  • vkm
    vkm over 9 years
    try @fasteque answer in the above link
  • andrew
    andrew over 9 years
    Have already been through the steps in that question. I know ADB is working and connecting fine. I have even tried to build my debug apk, install it through ADB then attach remotely, but this failed too
  • snark
    snark over 9 years
    Does it have to be the latest JDK? I'm using Oracle JDK 7 update 71 and have removed all the other JDKs from my ubuntu 14.04 system. But Android Studio still won't reliably let me debug my app. Like andrew I see "Connected to the target VM" but I can't step into or over code or stop at breakpoints. I say 'reliably' because sometimes it does work, but 8 times out of 10 it doesn't and I don't know why - very frustrating! Any ideas what might be wrong please?
  • fix
    fix over 7 years
    After adding lines and lines of nonsense to my proguard-rules.pro file, this ended up being the problem all along. Thank you.