简体   繁体   English

Android工作室无法渲染布局预览

[英]Android studio not rendering layout preview

I've been using Android Studio 0.8.6 to develop apps and am having problems with the layout preview when using API21. 我一直在使用Android Studio 0.8.6来开发应用程序,并且在使用API​​21时遇到布局预览问题。 I get the following error: 我收到以下错误:

Rendering Problems: The following classes could not be instantiated: - android.support.v7.widget.Toolbar 呈现问题:无法实例化以下类: - android.support.v7.widget.Toolbar

I have SDK Build tools up-to-date (21.0.2) as well as the full API21 downloaded and installed. 我有最新的SDK Build工具(21.0.2)以及下载和安装的完整API21。 My targetSDKVersion is set to 21 on the gradle file. 我的targetSDKVersion在gradle文件中设置为21。 If I change the preview to render with API20, everything seems fine. 如果我将预览更改为使用API​​20渲染,一切似乎都很好。 Exception details are provided below. 下面提供了异常详细信息。

Thanks! 谢谢!

Exception Details java.lang.ClassNotFoundException: android.support.v4.content.ContextCompatApi21 at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:148) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:319) at android.support.v7.internal.widget.TintManager.getDrawable(TintManager.java:133) at android.support.v7.internal.widget.TintTypedArray.getDrawable(TintTypedArray.java:62) at android.support.v7.widget.Toolbar.(Toolbar.java:248) at android.support.v7.widget.Toolbar.(Toolbar.java:190) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64) at android.view.LayoutInflater.rInflate(LayoutInflater.java:782) at android.view.LayoutInflater.in 异常详细信息java.lang.ClassNotFoundException:android.support.v4.content.ContextCompatApi21 at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:148)at java.lang.ClassLoader.loadClass(ClassLoader.java:424) )位于android.support.v7.intent.widget.TintManager.getDrawable的android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:319)的java.lang.ClassLoader.loadClass(ClassLoader.java:357) TintManager.java:133)在Android.support的android.support.v7.internal.widget.TintTypedArray.getDrawable(TintTypedArray.java:62)android.support.v7.widget.Toolbar。(Toolbar.java:248)。 v7.widget.Toolbar。(Toolbar.java:190)位于android.view的android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)的java.lang.reflect.Constructor.newInstance(Constructor.java:408)中。 android.view.LayoutInflater.in中android.view.LayoutInflater.rInflate(LayoutInflater.java:782)的LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64) flate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:385) flate(LayoutInflater.java:504)在android.view.LayoutInflater.inflate(LayoutInflater.java:385)

This problem was back to me in Android Studio 1.2. 这个问题在Android Studio 1.2中回复给我。

This is what I did and worked. 这就是我所做的和工作。

  1. Clean Project 清洁项目
  2. Rebuild project 重建项目
  3. Sync Gradle 同步Gradle
  4. Press update layout preview button 按更新布局预览按钮

The most recent version of Android Studio is 0.8.14 and this fixes a number of issues with API21. 最新版本的Android Studio是0.8.14 ,这修复了API21的一些问题。 Note that as per the Android Studio 0.8.12 announcement (under 'No patches'): 请注意,根据Android Studio 0.8.12公告 (在“无补丁”下):

We've found and fixed several significant bugs in the patching mechanism. 我们已经找到并修复了修补机制中的几个重要错误。 One of these bugs meant that upgrading to a new version, while resulting in a functionally identical installation, would also result in slightly different binary contents (for example, some timestamps inside .jar files would differ). 其中一个错误意味着升级到新版本,同时导致功能相同的安装,也会导致二进制内容略有不同(例如,.jar文件中的某些时间戳会有所不同)。 This meant that the actual binary signatures would not match, which broke for example the application signature checks. 这意味着实际的二进制签名不匹配,这例如打破了应用程序签名检查。

We have now found and fixed that bug, but because there are many different binary variations of a given previous version, we cannot create a single patch to update to the new version. 我们现在已经找到并修复了该错误,但由于给定先前版本存在许多不同的二进制变体,因此我们无法创建单个补丁来更新到新版本。 Therefore, for this version we will require a full download of the IDE. 因此,对于此版本,我们将需要完整下载IDE。 From this version forward we should be able to accurately install updates while preserving the application signatures. 从此版本开始,我们应该能够在保留应用程序签名的同时准确安装更新。

So you'll need to manually install the latest build . 因此,您需要手动安装最新版本

Try unselecting "Automatically pick Best" in the Preview pane and select an older API when you view your layout XML. 尝试在“预览”窗格中取消选择“自动选择最佳” ,并在查看布局XML时选择较旧的API。 This is located in the menu bar where you select the device and theme you want your preview to use, all the way on the right. 它位于菜单栏中,您可以在其中选择要预览使用的设备和主题,一直在右侧。

将样式父级更改为Theme.AppCompat.Light.NoActionBar而不是styles.xmlTheme.AppCompat.Light.DarkActionBar .........它对我Theme.AppCompat.Light.DarkActionBar

This is a known issue , see below. 这是一个已知问题 ,见下文。

Spurious Render Exception 虚假渲染异常

The specific render error message is: The following classes could not be found: 特定的呈现错误消息是:找不到以下类:

android.support.v7.internal.app.WindowDecorActionBar

Despite the error message, the layout preview is correct and the message can be safely ignored . 尽管出现错误消息,但布局预览正确并且可以安全地忽略消息 The issue has already been fixed in 2.0 preview. 该问题已在2.0预览中修复。 See bug 192102 for more details . 有关详细信息,请参阅 错误192102 (Issue link is not valid anymore). (问题链接不再有效)。

I'm facing the same problem in android studio 2.2 我在android studio 2.2中遇到了同样的问题

This is what I did and nothing 这就是我所做的,没有

-Clean Project - 清洁项目

-Rebuild project - 重建项目

-Sync Gradle -Sync Gradle

The only thing that actually worked for me was Restarting android studio (close and reopen) 唯一对我有用的是重启android studio(关闭并重新打开)

  1. Clean Project 清洁项目
  2. Rebuild project 重建项目
  3. Sync Gradle 同步Gradle
  4. Press update layout preview button 按更新布局预览按钮

The "Update layout preview" button is located above the android phone preview, it's the one with circular blue arrows, right by the magnifying glass zoom buttons. “更新布局预览”按钮位于Android手机预览上方,它是带有圆形蓝色箭头的按钮,右侧是放大镜缩放按钮。

note: this solution appears to do nothing until the update layout button is pressed at the final step, and then it works. 注意:在最后一步按下更新布局按钮之前,此解决方案似乎无效,然后它才有效。 This fixed the problem for me. 这解决了我的问题。 I am using Android Studio v2.1.2. 我使用的是Android Studio v2.1.2。

Cheers! 干杯!

  • Clean Project 清洁项目
  • Rebuild project 重建项目
  • Sync Gradle 同步Gradle
  • Press update layout preview button 按更新布局预览按钮

Or 要么

in your XML file press right click and mark as XML. 在您的XML文件中按右键并标记为XML。

that should work. 应该工作。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM