这个问题造成了在Idea中开发Android项目,无法对页面布局预览,看了很多解决办法,主要集中在重启、Invalidate Caches...、删除.idea目录上,但是这都无效。
在Idea的log中查看到如下信息:
2024-09-04 17:17:18,285 [ 48177] INFO - #c.i.i.p.m.MarketplaceRequests - Cannot get the list of JetBrains plugins from Marketplace: Connect timed out
2024-09-04 17:17:22,595 [ 52487] SEVERE - #o.j.a.s.StudioEmbeddedRenderTarget - Unable to find embedded layoutlib in paths:
[/Applications/IntelliJ IDEA.app/Contents/plugins/design-tools//resources/layoutlib/, /Users/youname/Library/Caches/JetBrains/IntelliJIdea2023.3/android/layoutlib-resources/231.0.26.0/plugins/android/resources/layoutlib]
java.lang.Throwable: Unable to find embedded layoutlib in paths:
[/Applications/IntelliJ IDEA.app/Contents/plugins/design-tools//resources/layoutlib/, /Users/yourname/Library/Caches/JetBrains/IntelliJIdea2023.3/android/layoutlib-resources/231.0.26.0/plugins/android/resources/layoutlib]
也就是在加载这个layoutlib-resources的目录没有找到内容。
下载了这个 layoutlib-resources,你应该将这个jar包解压,并放到
/Users/yourname/Library/Caches/JetBrains/IntelliJIdea2023.3/android/layoutlib-resources/231.0.26.0/
目录下,重新刷新页面预览,可以看到效果了。
资源在顶部可以下载。