简体   繁体   English

Android Studio (海豚 | 2021.3.1) & (电鳗 | 2022.1.1) 不显示布局预览

[英]Android Studio (Dolphin | 2021.3.1) & (Electric Eel | 2022.1.1) does not show layout preview

I'm using Android Studio Dolphin |我正在使用 Android Studio Dolphin | 2021.3.1 & Electric Eel | 2021.3.1 & 电鳗 | 2022.1.1 2022.1.1

After updating Android studio chipmunk |更新后 Android studio chipmunk | 2021.2.1 to Android studio Dolphin | 2021.2.1 至 Android 工作室海豚 | 2021.3.1 my all project design preview and layout preview not showing. 2021.3.1 我的所有项目设计预览和布局预览都没有显示。 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.重启IDE。
  3. Repair IDE.维修IDE。
  4. Update Gradle plugin version to 7.3.0 from setting project structure (No working)从设置项目结构更新 Gradle 插件版本到 7.3.0(没有工作)

Check the Below screenshot so everyone gets an idea of what I have issue faced.查看下面的屏幕截图,以便每个人都了解我遇到的问题。

在此处输入图像描述

Thanks in advance.提前致谢。

For me, some layouts are working fine but in some layouts, I am getting the below error which used to work in earlier versions of Android Studio.对我来说,某些布局工作正常,但在某些布局中,我收到以下错误,该错误曾在 Android Studio 的早期版本中出现。

在此处输入图像描述

The same issue I faced in Android (Electric Eel | 2022.1.1).我在 Android(电鳗 | 2022.1.1)中遇到了同样的问题。 Still, this Issue continues.尽管如此,这个问题仍在继续。

I was able to fix that error by downgrading API versions.我能够通过降级API 版本来修复该错误。
API 33 to API 28. API 33 至 API 28。
And then Invalidate Cache Restart.然后无效缓存重新启动。

I tried to update gradle but not work with me.我试图更新 gradle 但没有与我一起工作。

so after that i changed them from所以在那之后我把它们从

Theme.MaterialComponents.DayNight.NoActionBar

to

Theme.Material3.DayNight.NoActionBar

work with me和我一起工作

if this solution does not work with you如果此解决方案对您不起作用

add this line to root group view in layout将此行添加到布局中的根组视图

android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.Bridge"

another solution另一种解决方案

down material version to this version down material版本到这个版本

material_version = '1.6.1'

I hope that helps you.我希望这对你有帮助。

To solve temporary this issue.暂时解决这个问题。 Change theme for preview using "AppTheme".使用“AppTheme”更改预览主题。 This is work for me.这是为我工作。 For detail see the attachment file image有关详细信息,请参阅附件图像

在此处输入图像描述

在此处输入图像描述

I had the same issue and solved it by ignoring some errors in the issue panel我有同样的问题并通过忽略问题面板中的一些错误来解决它

在此处输入图像描述

Not this specific issue, this is for example sake不是这个具体问题,这是为了举例

After alot of searching and testing, I upgraded my gradle version and its work for me.经过大量搜索和测试,我升级了我的 gradle 版本及其对我的工作。

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只需转到File -> Project Structure或按Ctrl + Alt + Shift + S然后upgrate the gradle version ,如下图所示,然后invalidate cache and restart Android Studio 及其工作

在此处输入图像描述

As shown in the image I upgrade my gradle如图所示,我升级了我的 gradle

Happy Coding With Android Studio:) Android Studio 的快乐编码:)

Downgrade to Android Studio Chipmunk (2021.2.1) Patch 2 https://developer.android.com/studio/archive降级到 Android Studio Chipmunk (2021.2.1) 补丁 2 https://developer.android.com/studio/archive

It will work after that.之后它将起作用。

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我可以通过将预览的主题从 App.Starting [默认] 更改为设计选项卡中的应用程序主题来解决此问题

在此处输入图像描述

It appears to be a bug in Dolphin in connection with API 33, but for me at least the layout preview toolbar is shown.这似乎是 Dolphin 中与 API 33 相关的错误,但对我来说,至少显示了布局预览工具栏。 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.如果可以以某种方式访问预览工具栏,则以下解决方法可以解决消失的预览(至少对我而言):布局工具栏中的 Select API 32而不是预选的 ZDB974238714CA8DE634A7CE1D083A1。

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.然后预览会按原样显示给我,我不必降级任何东西,并且可以使用最新的 gradle 版本。

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. 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在您的模块中。

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.如果您在问题面板中看到java.lang.NoSuchFieldError: view_tree_lifecycle_owner ,请确保在模块中包含对androidx.lifecycle:lifecycle-runtime的 debugImplementation 依赖项。

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. 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在你的模块中。

Issue tracker: https://issuetracker.google.com/issues/247058594问题跟踪器: https://issuetracker.google.com/issues/247058594

In my case, the android studio can't show the XML if it contains " include " tag.就我而言,如果 android 工作室包含“ include ”标签,则无法显示 XML。

My project have more than 100+ XML files which has the include , and non of them can show the preview.我的项目有 100 多个 XML 文件,其中include ,并且没有一个可以显示预览。 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.更改 AGP 版本并增加 Gradle 版本,如果您还没有在项目结构 > 项目到最新版本中单击应用并等待 gradle 完成。 After completing, Just Invalidate Cache and restart.完成后,只需使缓存无效并重新启动。 It worked for me.它对我有用。

在此处输入图像描述

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设置- SDK 工具并检查Android 模拟器更新只是更新它并重建项目并完成

No need to downgrade API versions .无需降级API 版本

在此处输入图像描述

Note - if not work after it just try to invalidate cach and restart注意 - 如果在尝试使缓存无效并重新启动后不起作用

Option 2选项 2

after doing above task try to just update or select app theme from above preview design完成上述任务后,尝试从上述预览设计中更新或 select 应用程序主题在此处输入图像描述

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.将 Android Gradle 插件切换到所有项目的7.3.0和 gradle 的7.4可以解决此问题。

Layouts with include tags are not working and there are many bugs in the preview in dolphin.带有包含标签的布局不起作用,并且在 dolphin 的预览中存在许多错误。 I think they should give an update to fix all that.我认为他们应该提供更新以解决所有这些问题。

In my case solve this issue I do following steps就我而言,解决此问题我执行以下步骤

First I just update Gradle plugin version to 7.3.0 from setting project structure (No working)首先,我只是通过设置项目结构将Gradle 插件版本更新为7.3.0 (No working)

after that I also update com.google.gms:google-services version to 4.3.14之后我还将com.google.gms:google-services版本更新为4.3.14

now every things work fine.现在一切正常。

I was using custom views, styles and fonts from a library and ran into this when upgrading to Dolphin.我使用库中的自定义视图、样式和字体,在升级到 Dolphin 时遇到了这个问题。 I fixed the issue by upgrading the libraries compile SDK to 33. Upgraded gradle to 7.3 and upgraded androidx.appcompat:appcompat to 1.4+我通过将库编译 SDK 升级到 33 来解决这个问题。将 gradle 升级到 7.3 并将 androidx.appcompat:appcompat 升级到 1.4+

Once you do that, invalidate caches and rebuild and it should work.执行此操作后,使缓存无效并重建,它应该可以工作。

Google is aware of this issue https://issuetracker.google.com/issues?q=dolphin%20layout%20preview谷歌知道这个问题https://issuetracker.google.com/issues?q=dolphin%20layout%20preview

Downgrading to Chipmunk until a patch is released will also fix the issue if you can't or wont upgrade.如果您不能或不愿升级,则在发布补丁之前降级到 Chipmunk 也可以解决问题。

Try to remove/modify any drawable resource files that you are using as style/background in your layout.尝试删除/修改您在布局中用作样式/背景的任何可绘制资源文件。 It may cause Render problem/Touch size/Touch Target too small.这可能会导致渲染问题/触摸尺寸/触摸目标太小。 In my case I was using such resource files, after modifying those, the layout is visible to me.在我的例子中,我使用了这样的资源文件,在修改这些文件之后,布局对我来说是可见的。 Thanks.谢谢。

Try to upgrade your gradle version to latest (whatever it may be).尝试将您的 gradle 版本升级到最新版本(无论它是什么)。 Mine Worked我的工作

Use material:1.8.0-alpha01 dependency.使用material:1.8.0-alpha01依赖项。 alpha02 has issue showing preview. alpha02 在显示预览时出现问题。

If all these solutions are not working then you can try below option as well.如果所有这些解决方案都不起作用,那么您也可以尝试以下选项。 Disable lottieAnimation in the xml file, and reBuild the app, then it is working fine now.在 xml 文件中禁用 lottieAnimation,然后重新构建应用程序,然后它现在可以正常工作了。

For you that because of others dependencies cannot update the Android Gradle Plugin:对于因为其他依赖项而无法更新 Android Gradle 插件的您:

You'll have to wait a little bit, the devs are already aware.您需要稍等片刻,开发人员已经知道了。 There should eventually be a version to correct this.最终应该有一个版本来纠正这个问题。

For now what you can do to keep working is downgrading the Android Studio Version to Chipmunk |现在你可以做的是将 Android Studio 版本降级到Chipmunk | 2021.2.1 (or older) 2021.2.1 (或更早)

Maybe it's not going to fix your problem.也许它不会解决您的问题。 But it may helps someone who gets into the same trouble as I had.但这可能会帮助那些遇到和我一样麻烦的人。 I have an extended layout, the exception says it's not able to initial this class, and pointing to a singleton property variable.我有一个扩展布局,异常表示它无法初始化此类,并指向一个单例属性变量。

private SingletonProperty property = SingletonProperty.getInstance();

Turns out it's not possible to have a singleton field in a layout class(which it's okay before Android Studio Dolphin).原来在布局类中不可能有单例字段(在 Android Studio Dolphin 之前没问题)。 Everything works fine after I move it into several methods.在我将其移至多种方法后,一切正常。 Don't forget to build your project after this.在此之后不要忘记构建您的项目。

For me, disabling assertions fixed the issue.对我来说,禁用断言解决了这个问题。
I found the fix here: https://issuetracker.google.com/issues/255525863我在这里找到了修复: https ://issuetracker.google.com/issues/255525863
To disable assertions, add -da to Custom VM Options:要禁用断言,请将-da添加到自定义 VM 选项:

在此处输入图像描述


In case that Android Studio won't start after applying the new options,如果应用新选项后 Android Studio 无法启动,
the custom VM options file is located at:自定义 VM 选项文件位于:

macOS:苹果系统:

~/Library/Application Support/Google/AndroidStudio2021.3/studio.vmoptions

Apparently, there are many people reporting the exact same issue to Google but no concrete solution has been given so far:显然,有很多人向谷歌报告了完全相同的问题,但目前还没有给出具体的解决方案:

I tried most of the suggestions from the other answers, but the only thing that has worked for me so far was upgrading to Flamingo ( 2022.2.1 Canary 10 ) or downgrading to Chipmunk ( 2021.2.1 Patch 2 ).我尝试了其他答案中的大部分建议,但到目前为止唯一对我有用的是升级到Flamingo ( 2022.2.1 Canary 10 ) 或降级到Chipmunk ( 2021.2.1 Patch 2 )。

These solutions are obviously far from ideal, but until Google decides to fix this in either Dolphin or Electric Eel , I believe that's what we're stuck with.这些解决方案显然远非理想,但在 Google 决定在DolphinElectric Eel中修复此问题之前,我相信这就是我们所坚持的。

I had the same problem if you are using custom views in your layout, checkout this answer https://stackoverflow.com/a/66337620/14599955 .如果您在布局中使用自定义视图,我会遇到同样的问题,请查看此答案https://stackoverflow.com/a/66337620/14599955

在此处输入图像描述

Open Layout Validation tab from right side or search it from toolbar search menu now see the issue in my case is inside MaterialAutoCompleteTextView after investigating issue is android:fontFamily="More Fonts..." font is not point to right one从右侧打开 Layout Validation 选项卡或从工具栏搜索菜单中搜索它现在看到我的问题在 MaterialAutoCompleteTextView 内部,调查问题是 android:fontFamily="More Fonts..." 字体没有指向正确的字体在此处输入图像描述

Don't use alpha version.不要使用 alpha 版本。 Use this用这个

implementation 'com.google.android.material:material:1.7.0'

I also had the problem of the layout page not appearing and it was not solved in any way until I made a copy of it and deleted the entire layout one by one to find out which view had the problem.我也有布局页面没有出现的问题,直到我复制它并一个一个地删除整个布局以找出哪个视图有问题,它才以任何方式解决。 It is interesting that the copy of the layout was intact and worked exactly.有趣的是,布局的副本完好无损并且可以正常工作。

Frankly guys tried everything as suggested in mentioned answers, but doesn't seems to work for me, might be a recent Android Studio bug.坦率地说,伙计们按照提到的答案中的建议尝试了一切,但似乎对我不起作用,可能是最近的 Android Studio 错误。

Sharing something what worked for me (workaround, not a fix)分享对我有用的东西(解决方法,而不是修复)

I accidentally clicked the LayoutValidation tab as mentioned in screenshot, and for now using it to preview my design while updating XML code.我不小心点击了屏幕截图中提到的LayoutValidation选项卡,现在使用它来预览我的设计,同时更新 XML 代码。 Preview gets updated as you make changes.预览会在您进行更改时更新。

But yes this might not be helpful if want to make changes using design.但是,是的,如果想使用设计进行更改,这可能没有帮助。

在此处输入图像描述

build.gradle(Project) build.gradle(项目)

buildscript {
    dependencies {
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
    }
}

plugins {
    id 'com.android.application' version '7.3.0' apply false
    id 'com.android.library' version '7.3.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
    id 'com.google.gms.google-services' version '4.3.13' apply false
}

build.gradle(app)构建.gradle(应用程序)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'kotlin-android-extensions'
    id 'dagger.hilt.android.plugin'
    id 'com.google.gms.google-services'
}

android {
    compileSdkVersion 31
    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
}   

if you use dagger/hilt pls updata below library如果您使用匕首/刀柄,请在库下方更新数据

    kapt "com.google.dagger:dagger-compiler:2.42"
    kapt "com.google.dagger:hilt-android-compiler:2.43.2"
    implementation "com.google.dagger:dagger:2.42"
    implementation "com.google.dagger:hilt-android:2.43.2"
    implementation 'androidx.hilt:hilt-work:1.0.0'
    kapt "androidx.hilt:hilt-compiler:1.0.0"
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
    implementation "androidx.navigation:navigation-compose:2.5.1"

gradle-weapper.properties gradle-weapper.properties

distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

setting.gradle设置.gradle

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()

        maven { url 'https://jitpack.io' }
        maven { url "https://plugins.gradle.org/m2/" }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }

    }
}
include ':app'

The only way that rendering of XML is going to work is by clearing out all the errors from the issue panels, which in your case from the photo are 4 errors.渲染 XML 的唯一方法是清除问题面板中的所有错误,在您的情况下,照片中有 4 个错误。 This worked for me这对我有用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android XML 布局预览在 Android Studio Dolphin 2021.3.1 补丁 1 中不起作用 - Android XML layout preview not working in Android Studio Dolphin 2021.3.1 Patch 1 将 Android Studio 更新为 Dolphin 更新后,它不显示布局预览 - After updating Android Studio to Dolphin update it does not show layout preview Android Studio Dolphin 2021.3.1:构建项目时出错 - Android Studio Dolphin 2021.3.1: Error while building project Android Studio 海豚 | 2021.3.1 补丁 1 设备管理器模拟器损坏和失真 - Android Studio Dolphin | 2021.3.1 Patch 1 device manager emulator is broken and distorted 如何在 Dolphin 中启用 android studio new logcat | 2021.3.1 金丝雀 6? - How to enable android studio new logcat in Dolphin | 2021.3.1 Canary 6? Android Studio 不显示布局预览 - Android Studio does not show layout preview Android Studio 3.1 布局预览不显示某些布局的预览 - Android Studio 3.1 layout preview does not show preview for some layouts 使用外部系统时出现异常:Android Studio Dolphin 中的 java.lang.AssertionError | 2021.3.1 - Exception during working with external system: java.lang.AssertionError in Android Studio Dolphin | 2021.3.1 在编辑配置中找不到调试器选项卡(Android Studio Dolphin | 2021.3.1 补丁 1) - cannot find Debugger tab in Edit Configurations (Android Studio Dolphin | 2021.3.1 Patch 1) Internal Error occurred while analysing this expression error in Android 海豚工作室 2021.3.1 - Internal Error occurred while analyzing this expression error in Android Studio Dolphin 2021.3.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM