Android Layout Inspector fails with timeout error - android

When I try to inspect my application's layout in a simulator, by going Tools => Layout Inspector, it always fails with one of the errors:
1.
Error obtaining view hierarchy: There was a timeout error capturing the layout data from the device.
The device may be too slow, the captured view may be too complex, or the view may contain animations.
Please retry with a simplified view and ensure the device is responsive.
2.
No active windows displayed by com.instabridge.android.dev
The layout is not particularly complex, and it does not contain animations, just map with some views. Android Studio is 3.4.1. How do I fix it? Or how to find the cause of the errors?

Found a really strange solution.
Open your app, go to android home screen, open another app, now use Layout inspector in Android Studio.
It worked and I see my app's view hierarchy.
UPDATE
P.Melch claims that you don't even need to open another app, try just sending your app to background.

I had the same issue on Android Studio 3.4, but I was able to use the Layout Inspector on Android Studio 3.5 Beta 1 without any problems.
I am working with a very complex view, so I suspect that is what led to the trouble on Android Studio 3.4. Both the failure I saw and the success were with a physical device.

Try to use a real device instead of the simulator.
When running the simulator and android studio, your laptop/mac/whatever might be running out of memory.
I always prefer to run the layout inspector on a real physical device. It works the same as with the emulator once you're connected with adb

Related

Layout messed up after opening another layout. Render problem

I'm working on a project for the last 2 weeks, everything was going fine until today. When I started my PC and opened Android Studio I noticed that when I open another layout the first layout gets messed up with an error Render problem. If I refresh the layout then everything becomes fine but the other layout gets messed up.
When I run the app on emulator or actual device it is working as it supposed to be.
Here is the screen recording:
Screen recording of the actual problem
Note: I'm new to this platform and don't know how to upload videos. Please ignore the low resolution of the GIF.
Here is what I tried:
Invalided cache and restated android studio.
Restarted my PC.
Checked for graphics card update.
But nothing helped.
Additional info:
I'm using Constraint layout, but I'm 100% sure that's not the cause.
I'm using Stable version of android studio. (Android Studio Arctic Fox | 2020.3.1 Patch 3)

While running the application on android device, controls do not display properly as designed in android studio

I have been facing this issue while creating any android program/app using android studio. Whatever I design in android studio, it is not displaying properly as designed in android studio while running the app on my phone.
In short, sometimes size and the places of the controls get changed while running the app on my android phone. Please help. Thank you.
That's probably because of the difference in screen sizes of your preview and your physical phone . I've recently started using constraint layout and I think it's the best so far, a bit confusing at first but easy to understand it, it even has an option for percentage of width/height of the total screen for a view. Try that out.

Android Studio 2.3.3 issue where the virtual phone UI appears in the top left of the virtual phone, but functions correctly

Hey, this is an example of the issue I'm having with Android Studio. I dont think I have made any changes from my first few programs which worked fine and the UI filled the whole Emulator screen
This is the 4th ever app I've written for a web dev class with android studio. I have written 3 other apps that did not have this issue with the phone. But after starting up android studio today to work on the next project for a class the issue in the picture would take place. The Virtual phone works properly but just has a very badly sized image instead of the full virtual phone screen.
I've sent a copy of the program I've been working on to my professor, but haven't heard back yet. Ive also tried to uninstall and reinstall Android Studio but the issue still remains. If anyone can give me a few hints or help in resizing the image to the correct size in the Emulator it would be much appreciated. Thank you very much.

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.
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
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.

Android emulator as window inside Eclipse

Is it possible to put the emulator inside eclipse, as a tab/window? I've got dual monitors and my typical setup is eclipse full screen on one side and chrome full screen on the other one typically on an developer.android.com or stackoverflow and the emulator UNDER chrome most of the time until I'm debugging.
I do not know if it is possible in Eclipse, most probably not (I could be wrong).
You can try out MotoDevStudio though. The development environment looks exactly like Eclipse, so you wouldn't have much trouble switching over. And more importantly, it has the Android Emulator running inside a tab in the IDE.

Categories

Resources