25

I am just switching from Eclipse to Android Studio and found this weird behavior. When I add a breakpoint in the first line of a method, I cannot see the parameter values. The only thing I can see then is the this reference. I either have to make one debug step or set the breakpoint to a line after the first one to see the parameter values.

Anyone else has this problem or knows what's going wrong here?

SimonSays
  • 10,867
  • 7
  • 44
  • 59

8 Answers8

39

Try turning off your jacoco test coverage off for the debug build in your build.gradle file:

debug {
    ...
    testCoverageEnabled false
}

This completely fixed the issue for me where upgrading the gradle plugin did not.

Rhys Davis
  • 996
  • 7
  • 16
  • This worked for me. BTW, this snippet should be in the app build script, mine is in the "android" section of that script. The android issue tracker includes issue [177480](https://code.google.com/p/android/issues/detail?id=177480&q=debug%20arguments&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars) which includes this answer, as well as some other recommendations on the topic. – OYRM Jan 09 '16 at 22:09
  • Don't know why, but this seems to have worked for me too. So the problem is jacoco? – SMBiggs Feb 10 '16 at 17:42
  • this should be the accepted answer, am using gradle plugin 2.0.0 and still had this issue. This one fixed it for me. – kev Jun 28 '16 at 07:35
  • 2
    Worked for me. Why is this happening though... I shouldn't have to turn off jacoco to debug -.- – Ryan Newsom Sep 09 '16 at 16:49
7

A good solution until AOSP Issue #123771 is solved, is to use the snippet provided by Stuart in the comments section:

buildTypes {
    debug {
        [...]
        testCoverageEnabled true
    }
    release {
        [...]
    }
    debuggable.initWith(buildTypes.debug)
    debuggable {
        testCoverageEnabled false
    }
}

This way you can both keep your test coverage reports in your debug build and have a way of stepping through code seeing your local variables.

2

I don't have in my gradle file:

debug {
    ...
    testCoverageEnabled true
}

but had the same issue on Android Studio 2.2. Solution that helped me to resolve issue:

  1. Disable Instant Run in IDEA Settings.
  2. Re-build project.
  3. Enable Instant Run.
IgorOK
  • 1,652
  • 4
  • 18
  • 36
  • 1
    I had Instant Run disabled because of this https://stackoverflow.com/questions/40618803/android-app-crashes-when-launched-in-debug-mode and then breakpoints worked again after reenabling. – rob5408 Oct 17 '17 at 19:25
1

The solution provided by Google here is to upgrade the Android Studio Gradle plugin to v1.0.1

SimonSays
  • 10,867
  • 7
  • 44
  • 59
1

If your build uses the jack toolchain this can be the source of the problem. In my case, disabling jack solves the problem:

buildTypes {
...
    debug {
        jackOptions {
            enabled false
        }
    }
}

Note: 1.8 source compatibility requires jack!

1

I got sick of toggling testCoverageEnabled when I wanted to debug so set up a project property to disable it when run from Android Studio, but default to enabled when run from command line with no options such as on a build box.

// Default to true, set -PtestCoverageEnabled=false in IDE compiler command-line options
def isTestCoverageEnabled = { ->
    def enabled = project.hasProperty('testCoverageEnabled') ? testCoverageEnabled.toBoolean() : true
    println "testCoverageEnabled = " + (enabled ? "true" : "false")
    return enabled
}

android {
    buildTypes {
        debug {
            testCoverageEnabled isTestCoverageEnabled()
        }
    }
}

To set the property in the IDE add the command-line option -PtestCoverageEnabled=false

Android Studio -> Preferences -> Build, Execution, Deployment -> Compiler -> Command-line Options

darnmason
  • 2,672
  • 1
  • 17
  • 23
0

I ran into this issue when trying to debug an app that was previously installed using an APK and not from Android Studio itself. Fixed it by uninstalling the app and re-run the debug.

Chin
  • 19,717
  • 37
  • 107
  • 164
0

Following configuration worked for me for buildType release.

buildTypes {

release{

testCoverageEnabled = false

debuggable true

minifyEnabled false

shrinkResources false

}

DkPathak
  • 452
  • 1
  • 4
  • 16