简体   繁体   English

Android Studio无法渲染布局

[英]Android Studio not rendering layout

I have started a new android studio project and on opening of the main activity, the design view shows this error and does not show the layout on the emulator: 我已经开始了一个新的android工作室项目,并且在打开主要活动时,设计视图显示了这个错误并且没有在模拟器上显示布局:

org.jetbrains.android.uipreview.RenderingException: Failed to load the LayoutLib: com/android/layoutlib/bridge/Bridge : Unsupported major.minor version 52.0 at org.jetbrains.android.uipreview.LayoutLibraryLoader.load(LayoutLibraryLoader.java:90) at org.jetbrains.android.sdk.AndroidTargetData.getLayoutLibrary(AndroidTargetData.java:180) at com.android.tools.idea.rendering.RenderService.createTask(RenderService.java:166) at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$6.run(AndroidDesignerEditorPanel.java:475) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310) at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227) at com.intellij.util.ui.update. org.jetbrains.android.uipreview.RenderingException:无法加载LayoutLib:com / android / layoutlib / bridge / Bridge:org.jetbrains.android.uipreview.LayoutLibraryLoader.load中不支持的major.minor版本52.0(LayoutLibraryLoader.java:90 )位于com.intellij.android.designer的com.android.tools.idea.rendering.RenderService.createTask(RenderService.java:166)的org.jetbrains.android.sdk.AndroidTargetData.getLayoutLibrary(AndroidTargetData.java:180)。 design.Surface.AndroidDesignerEditorPanel $ 6.run(AndroidDesignerEditorPanel.java:475)at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue) .java:310)at com.intellij.util.ui.update.MergingUpdateQueue $ 2.run(MergingUpdateQueue.java:254)at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)at com .intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)位于com.intellij.util.ui.update。 MergingUpdateQueue.run(MergingUpdateQueue.java:217) at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238) at com.intellij.util.Alarm$Request$1.run(Alarm.java:351) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:695) MergingUpdateQueue.run(MergingUpdateQueue.java:217)位于com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)com.intellij.util.Alarm $ Request $ 1.run(Alarm.java:351)at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:439)at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:303)at java.util.concurrent.FutureTask.run(FutureTask。 java:138)at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:895)at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:918)at java.lang.Thread.run (Thread.java:695)

What is the problem here? 这里有什么问题? Thanks. 谢谢。

Do you see the little Android icon? 你看到小Android图标吗?

Not the one in the top toolbar, the one in the toolbar just below it. 不是顶部工具栏中的那个,工具栏正下方的那个。 Click the little drop down triangle next to it and choose the correct API version! 单击旁边的小下拉三角形,然后选择正确的API版本!

That was all I needed to do. 这就是我需要做的一切。 The rendering took a while to load but it actually worked and the error message disappeared. 渲染需要一段时间才能加载,但它确实有效并且错误消息消失了。

You need to choose the correct API version. 您需要选择正确的API版本。

在此输入图像描述

Change your App theme in the theme options for DeviceDefault or DeviceDefault.Light. 在DeviceDefault或DeviceDefault.Light的主题选项中更改您的App主题。 This may works. 这可能有效。

Though I am not sure this might work. 虽然我不确定这可行。 I found few links where people have faced same issue. 我发现人们遇到同样问题的链接很少。

you have to choose a correct api level from the drop down. 你必须从下拉列表中选择正确的api级别。 this is the link 这是链接

Usually you get error: Unsupported major.minor version 52.0 通常你会收到错误:不支持的major.minor版本52.0

If you have installed Android N, change Android rendering version with older one and the problem will disappear. 如果您已经安装了Android N,请使用旧版本更改Android渲染版本,问题将消失。 enter image description here 在此输入图像描述

图片

Check that Java SDK version is the right one for Android Studio. 检查Java SDK版本是否适用于Android Studio。 Check that preview for layout is supported and you have sdk for that particular version of API you want to view. 检查是否支持布局预览,并且您有要查看的特定API版本的sdk。 Check that's not Android N on the preview, if it is, you probably don't have all SDKs you need. 检查预览中不是Android N,如果是,您可能没有所需的所有SDK。 Try installing them. 尝试安装它们。 Be sure to put in your question other details, as OS you are using, Java SDK you have installed, Android API SDKs you have. 请务必在您的问题中提供其他详细信息,如您使用的操作系统,已安装的Java SDK,以及您拥有的Android API SDK。

These are my dependencies and it works fine for me 这些是我的依赖,它对我来说很好

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'android.arch.core:runtime:1.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.firebaseui:firebase-ui-firestore:4.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile 'com.google.firebase:firebase-core:16.0.0'
apply plugin: 'com.google.gms.google-services'

} }

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

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