58

After Updating the android version 1.5 to 2.0 Preview4. Android studio Debugger unable to find the local variable defined in method definition. For reference, find the below screenshot.

enter image description here

MANISH PATHAK
  • 2,602
  • 4
  • 27
  • 31

7 Answers7

89

In your gradle, do you enable test coverage ?

    buildTypes {
        debug {
            testCoverageEnabled = true
        }
    }

Set testCoverageEnabled = false , it fixed the issue. https://code.google.com/p/android/issues/detail?id=78045

Raymond Chenon
  • 11,482
  • 15
  • 77
  • 110
  • Made AS see a pair of variables but further errors appear. – wtk Apr 18 '16 at 09:37
  • Thanks, it really helped! – G. Kh. Sep 05 '16 at 11:00
  • 2
    Thanks, this worked for me! Ended up creating a boolean based on if the build is running on a dev machine or a CICD server (based on the presence of environment variables in our build environment) so it can still provide test coverage reports on a build pipeline. – Ani Fichadia Nov 24 '16 at 06:31
  • @AniFichadia good idea. We do similar : set a environment variable on the CI , if this env. var. is not present ( on a developer's machine) the boolean default value is false. – Raymond Chenon Nov 24 '16 at 09:59
  • 1
    +100500 rep for this answer, saved me a lot of time. Thx – Andriy Jun 26 '17 at 07:42
  • In my case I had to put it to true when using jacoco if I want jacoco to produce coverage report. Put it back to false otherwise. Yeay! – Greg Feb 09 '18 at 12:44
  • I tried `create("customDebugType") {debuggable = true}` with and without `testCoverageEnabled = false`. I still get a wall of `view = Cannot find local variable 'view'` until it's done executing. I'm strugging to simply setup the ClickListener, and the items in the RecyclerView don't appear. – N.Barrett Dec 04 '22 at 02:46
11

Make sure you are not building a 'Release' Build Variant. You will get above warning when it is a Release Build.

Parinda Rajapaksha
  • 2,963
  • 1
  • 36
  • 40
9

if you have minifyEnabled true in

debug { minifyEnabled true debuggable true }

remove that and using just like that debug { debuggable true }

its work for me

6

Disable jack for debug build type (build.gradle):

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

Note: 1.8 source compatibility requires jack!

  • So, this means we cannot debug with Java 1.8, right? – francisco_ssb Jul 21 '16 at 15:11
  • No. It is possible to debug with java 1.8 and jack (breakpoints, step by step execution, etc.), but the values of the local variables are nor shown. Please note: my solution is a workaround not a resolution of the problem! – Miklós Keresztes Jul 22 '16 at 15:45
  • @Dori Android issue #93730 was closed as duplicate of another unrelated issue. I've created https://code.google.com/p/android/issues/detail?id=219615 as new issue related to "As soon as Jack & Jill are enabled, Android Studio does not show local variables and is unable to set breakpoints in library projects". – Flow Aug 09 '16 at 09:25
1

You can try this solution - open the Android Device Monitor, do a 'Reset adb'.

A screenshot where to find 'Reset adb'.

A screenshot where to find 'Reset adb'

Mykola
  • 435
  • 4
  • 17
1

Make sure that you build configuration with debuggable flag.

buildTypes {
    debug {
        minifyEnabled false
        debuggable true
    }
}
Danil Shaykhutdinov
  • 2,027
  • 21
  • 26
0

I got the problem , it was in build.gradle file

buildTypes { debug{ minifyEnabled true //This was the problem , make it false

    }
    release{

    }
}
Vivek Pratap Singh
  • 1,564
  • 16
  • 26