Can't start Android Studio Layout Inspector: “

2020-06-07 06:20发布

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.

9条回答
乱世女痞
2楼-- · 2020-06-07 06:44

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.

查看更多
ゆ 、 Hurt°
3楼-- · 2020-06-07 06:48

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.

查看更多
小情绪 Triste *
4楼-- · 2020-06-07 06:48

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.

查看更多
Emotional °昔
5楼-- · 2020-06-07 06:49

Had the same problem.

Could not capture hierarchy on Emulator.

I used a real device and it worked fine.

查看更多
我只想做你的唯一
6楼-- · 2020-06-07 06:55

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.

查看更多
姐就是有狂的资本
7楼-- · 2020-06-07 06:57

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.

查看更多
登录 后发表回答