4ndro1d
4ndro1d

Reputation: 2976

Android Studio 2.1 debugger does not show local variables

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

Upvotes: 31

Views: 21069

Answers (9)

Digvesh
Digvesh

Reputation: 9

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

Upvotes: 0

jcady
jcady

Reputation: 3968

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.

Upvotes: 2

Orlando G Rodriguez
Orlando G Rodriguez

Reputation: 517

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!

Upvotes: 15

Marline
Marline

Reputation: 269

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.

Upvotes: 5

BlackHatSamurai
BlackHatSamurai

Reputation: 23483

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

Upvotes: 1

lase
lase

Reputation: 2634

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.

Upvotes: -1

0wl
0wl

Reputation: 876

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

Upvotes: -1

vasquez
vasquez

Reputation: 449

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
        }
    }
}

Upvotes: 19

Cris Grange
Cris Grange

Reputation: 50

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'
}

Upvotes: -3

Related Questions