Android Studio Dolphin | 2021.3.1 does not show layout preview

Viewed 1363

I'm using Android Studio Dolphin | 2021.3.1

After updating Android studio chipmunk | 2021.2.1 to Android studio Dolphin | 2021.3.1 my all project design preview and layout preview not showing. If anyone solved this issue please help me.

I have tried all possible ways but didn't find any solution for this. Below are points that I have tried

  1. Invalidate caches.
  2. Restart IDE.
  3. Repair IDE.

Check the Below screenshot so everyone gets an idea of what I have issue faced.

enter image description here

Thanks in advance.

For me some layout are working fine but in some layout i am getting below error which used to work in earlier version on Android Studio.

enter image description here

11 Answers

After alot of searching and testing, I upgraded my gradle version and its work for me.

Just goto File -> Project Structure or press Ctrl + Alt + Shift + S and then upgrate the gradle version as shown in the image below and then invalidate cache and restart the Android Studio and its working

enter image description here

As shown in the image I upgrade my gradle.

I was able to fix that error by downgrading API versions.
API 33 to API 28.
And then Invalidate Cache Restart.

I was able to fix this by changing the preview's theme from App.Starting [default] to my app's theme from the Design Tab

enter image description here

It appears to be a bug in Dolphin in connection with API 33, but for me at least the layout preview toolbar is shown. In case the preview toolbar is somehow accessible, the following workaround solves the disappeared preview (at least for me): Select API 32 in the layout toolbar instead of the preselected API 33.

Then the preview is shown to me as it should and I do not have to downgrade anything and can use the latest gradle version.

Starting with Android Studio Chipmunk, if you're seeing java.lang.NoSuchFieldError: view_tree_saved_state_registry_owner or java.lang.ClassNotFoundException: androidx.savedstate.R$id in the issues panel, make sure to include a debugImplementation dependency to androidx.lifecycle:lifecycle-viewmodel-savedstate in your module.

If you're seeing java.lang.NoSuchFieldError: view_tree_lifecycle_owner in the issues panel, make sure to include a debugImplementation dependency to androidx.lifecycle:lifecycle-runtime in your module.

If you're seeing java.lang.NoClassDefFoundError: Could not initialize class androidx.customview.poolingcontainer.PoolingContainer or java.lang.NoClassDefFoundError: androidx/customview/poolingcontainer/PoolingContainerListener in the issues panel, make sure to include a debugImplementation dependency to androidx.customview:customview-poolingcontainer in your module.

Issue tracker : https://issuetracker.google.com/issues/247058594

Workaround Solution : File - Project Structure -

enter image description here

In my case, the android studio can't show the XML if it contains "include" tag.

My project have more than 100+ XML files which has the include, and non of them can show the preview. Otherwise, it was fine.

Change the AGP Version and Increase Gradle version if you have not in Project structure > Project to latest version the click apply and wait for gradle to complete. After completing, Just Invalidate Cache and restart. It worked for me.

enter image description here

I have same issue as above just solved by doing below things

Setting - SDK tools and check for Android Emulator Update just Update it and Rebuild project and Done

No need to downgrade API versions.

enter image description here

Note - if not work after it just try to invalidate cach and restart

Option 2

after doing above task try to just update or select app theme from above preview design enter image description here

I have also encountered this issue. Switching Android Gradle Plugin to 7.3.0 for all projects and 7.4 for gradle solve this problem.

Layouts with include tags are not working and there are many bugs in the preview in dolphin. I think they should give an update to fix all that.

Related