简体   繁体   中英

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"

在此输入图像描述

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

一般来说,当某些东西在视图中“移动”时,我就会出现这种情况,因此布局检查器无法检索到简单的布局,这就是为什么暂停视频会起作用的原因,但是如果你有更复杂的东西,比如相机预览或谷歌地图更难,不是确定如何解决这个问题

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 .

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

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.

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.

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 .

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.

Had the same problem.

Could not capture hierarchy on Emulator.

I used a real device and it worked fine.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM