Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't start Android Studio Layout Inspector: "Unexpected error: empty view hierarchy"

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.

like image 648
Marchy Avatar asked Jun 07 '17 13:06

Marchy


4 Answers

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

like image 171
JavierSP1209 Avatar answered Oct 11 '22 11:10

JavierSP1209


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.

like image 37
ashazar Avatar answered Oct 11 '22 12:10

ashazar


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

like image 4
Wayne Foks Avatar answered Oct 11 '22 12:10

Wayne Foks


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.

like image 3
yuliskov Avatar answered Oct 11 '22 11:10

yuliskov