42

Can't seem to launch Layout Inspector on Android Studio 3.0 (Canary 3)

When connected to my device and app running, choosing Tools > Android > Layout Inspector comes up with the following error dialog:

"Error obtaining view hierarchy: Unexpected error: empty view hierarchy"

enter image description here

Any setup I'm missing? I have Developer Options enabled on the device.

Marchy
  • 3,334
  • 5
  • 37
  • 27

9 Answers9

11

In general I've this behavior when something is "moving" in the view so the layout inspector cannot retrieve a simple layout, that's why pausing a video will work but if you have something more complex like camera preview or Google Map is harder, not sure how to work around this

JavierSP1209
  • 899
  • 8
  • 17
6

If you have ViewTreeObserver in your code to measure a view's width/height, and you're changing some width/height/padding/etc. according to a result you are getting from addOnPreDrawListener of ViewTreeObserver;

Just comment inside onPreDraw or comment all code related to ViewTreeObserver.

ashazar
  • 714
  • 5
  • 11
4

I can't launch my hierarchy viewer while playing video. Once I pause the video, it works!

Wayne Foks
  • 41
  • 2
  • I happened to meet that error as well on production Android Studio 3.0, in an activity after an activity having a live preview from camera. So far I haven't been able to come up with a solution to this – Antek Nov 20 '17 at 10:28
3

This could be related to your Android version. For example, in my case, this error occurs on Genymotion on Android 4. After moving to Android 5 this error gone.

yuliskov
  • 1,379
  • 15
  • 16
2

In my case, I had two devices connected to add, one device and an emulator. And I had to make sure only one device is connected. Then it worked. I was on Android Studio 3.2 Canary.

cgr
  • 4,578
  • 2
  • 28
  • 52
2

What I tried and did NOT work:

  • kill adb process and tried it again
  • clearing cache and restart
  • uninstalling the app, cleaning the build and building it again
  • disconnect the device and plug it back in

Finally I managed to solve it by turning off developer options and then turning it on + enable usb debugging.

arenaq
  • 2,304
  • 2
  • 24
  • 31
1

Had same problem on Android Studio v2.3.3, problem was related to CountDownTimer Object, somehow it cause problem (probably because of onTick method). After commenting it, I could normally use Layout Inspector. Maybe you use something similar in your code, try to comment it out and see if if works.

Nimdokai
  • 787
  • 1
  • 6
  • 18
0

Had the same problem.

Could not capture hierarchy on Emulator.

I used a real device and it worked fine.

Amir
  • 1,628
  • 20
  • 28
0

I changed my device from a Nexus 6 to a Pixel XL. Then it worked.

So try and change your device and see if that fixes the issue.

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54