Android Studio 2.1 debugger does not show local variables
Asked Answered
U

9

31

I am trying to debug over network in Android Studio. I connected via port 5555 and generally it is possible step through break points. But it often takes minutes just to execute one line of code and the other thing is that I don't see any variables which are no members. All I see is the this object, but no variables from within methods. How can I enable it?

enter image description here

As you can see I am within the method and at least the activity object is initialized, but it is not visible in the variables monitor.

UPDATE:

The problem remains when using USB debugging. No local variables are visible, not even when trying to evaluate expressions while debugging:

enter image description here

Android Studio 2.1, Gradle 2.1.0, Java 1.8

Uund answered 10/5, 2016 at 15:1 Comment(5)
So when you click on the + to the left of this is it not showing the variables within this?Polak
There are variables, but e.g. activity is a function variable which should definitely not be declared within this, but below as far as I rememberUund
You are right! Just tried it and activity is listed below this and not within. I'm stumped.Polak
I just figured out that the problem remains when switching back to USB as well... T_TUund
is this problem because of the new Jackson compiler? I just started experiencing this very annoying issue, and it's slowing down my development considerably.Disembody
R
19

Had the same problem.

There is a bug in Android Studio, see https://code.google.com/p/android/issues/detail?id=93730

They recommend removing in build.gradle (app), this fixed the issue for me.

android {
    buildTypes {
        debug {
            ...
            testCoverageEnabled true
        }
    }
}
Rana answered 14/12, 2016 at 15:12 Comment(2)
should be testCoverageEnabled falseStreaming
It works for me, thank. Seems like we can't use test coverage and debug at the same time, what an inconvenienceLivonia
B
15

After a while of figuring out this same issue, I realized I was running a release build rather than a debug build.

The build variants window may not be open in Android Studio by default. Go to Tool Windows -> Build Variants. In the Build Variants window, select the appropriate build.

In your app.gradle file, make sure debuggable is set to true in the build variant you would like to debug:

android {

   // ...

   buildTypes {

      release {
         // ...
      }

      debug {
         debuggable true
      }

   }

   // ...

}

If you would like to debug your release build, go ahead and add debuggable true to your release build.

Hope this helps!

Borgia answered 4/3, 2019 at 23:35 Comment(2)
The 1st paragraph of this answer hits the nail on the head. Had the same issue. Doh!Conceal
Always glad to help out!Borgia
D
5

I tried setting testCoverageEnabled to false but that did not work for me. In my case, I had ProGuard enabled for my debug flavor and disabling it (i.e. setting minifiyEnabled to false) was the only thing that allowed me to be able to see my local variables while debugging again.

During answered 5/3, 2018 at 21:51 Comment(0)
B
2

In my case, it was because I had forgotten that my build variant was set to release. Toggling the variant back to debug and re-running correctly showed the local variables.

Beatitude answered 20/6, 2019 at 22:30 Comment(0)
G
1

For me I had to set testCoverageEnabled to false like so:

android {
    buildTypes {
        debug {
            ...
            testCoverageEnabled false
        }
    }
}

When I had this set to true, I was not getting local variables

Gambit answered 28/9, 2017 at 20:59 Comment(1)
I have tried above solution its not worked for me ,still having issueLovegrass
H
0

I tried some kind of hit n trial and made it work with the settings as seen in the attachment. FYI, using latest version of Android Studio 3.3.1 and gradle version 4.6.

enter image description here

enter image description here

Horst answered 7/2, 2019 at 15:44 Comment(1)
Welcome to SO. You should 1) embed those images 2) provide some textual answer if they become unavailable.Bedell
W
-1

I had same trouble. I completely reinstalled my IDE and the trouble has been disappeared. I hope my approach will help you.

Wenger answered 27/1, 2017 at 14:26 Comment(1)
You probably just needed to update, which re-installing did for you.Literally
M
-1

While this is not a permanent solution to this problem, my most consistent fix (after trying the other answers here to no avail) has simply been restarting my computer.

Mertens answered 6/6, 2017 at 15:46 Comment(0)
L
-3

Java 1.8 does not support accessing variable values.

Update Gradle to version 2.2.0-beta3:

In your gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

In your project build.gradle file

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0-beta3'
}
Ligation answered 15/9, 2016 at 17:5 Comment(3)
Wait what? So I can't debug when using Java 1.8? So what does the gradle change do?Uund
You can debug with Java 1.8 but only using Gradle version 2.2.0 or aboveLigation
Please rephrase this answer, it is misleading.Carolincarolina

© 2022 - 2024 — McMap. All rights reserved.