10

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
  • 727
  • 1
  • 11
  • 21
  • Right click root folder in studio -> Open module settings -> Build Types. Do you have both debug and release builds added in the list? – prettyvoid Oct 17 '14 at 10:55
  • What's your JDK version? – prettyvoid Oct 17 '14 at 12:19
  • @Lenix: THAT'S IT!! You saved me!! It was because, although my JDK version was up to date, there were still old Java versions lying around. I've removed all versions of Java on my computer and did a completely new install and now it is all working!!! – andrew Oct 17 '14 at 16:42
  • Glad I helped. Please mark my answer accepted for future reference :) – prettyvoid Oct 17 '14 at 17:41
  • You can try to set debug type to **Java Only**. Read https://stackoverflow.com/a/63171238/3922207 – Anggrayudi H Jul 30 '20 at 10:30

3 Answers3

18

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

Pawel Cioch
  • 2,895
  • 1
  • 30
  • 29
  • After adding lines and lines of nonsense to my proguard-rules.pro file, this ended up being the problem all along. Thank you. – fix Jan 13 '17 at 20:39
4

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

prettyvoid
  • 3,446
  • 6
  • 36
  • 60
  • 1
    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? – snark Jan 18 '15 at 18:41
0

The gradle part is completely fine.I got the same code and he debugger works fine. How are you setting breakpoints? You just need to single click on the extreme left of the code window and a red ball would appear.

Refer : https://developer.android.com/sdk/installing/studio-debug.html

vkm
  • 548
  • 7
  • 23
  • 1
    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 – andrew Oct 17 '14 at 11:12
  • Refer : http://stackoverflow.com/questions/19517480/android-studio-debug-application-on-device – vkm Oct 17 '14 at 11:16
  • Yeah. I have tried but still nothing, apart from that it flags a warning telling me I shouldn't explicitly define this. – andrew Oct 17 '14 at 11:17
  • try @fasteque answer in the above link – vkm Oct 17 '14 at 11:18
  • 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 – andrew Oct 17 '14 at 11:20