2017-05-28 156 views
18

我刚开始学习Kotlin的android开发,并开始一个空的项目并添加了一个活动。如Kotlin文档中所述,我添加了所需的gradle依赖关系。默认情况下,MainActivity的xml文件只包含一个TextView。但是,当我尝试预览在布局编辑器中的XML显示一个“渲染错误”在Android Studio 3.0布局编辑器中渲染错误

Render problem 

Failed to load AppCompat ActionBar with unknown error. 

我也发现了此

The following classes could not be instantiated: 
- android.support.v7.widget.AppCompatImageView (Open Class, Show Exception, Clear Cache) 
- android.support.v7.widget.ActionBarContainer (Open Class, Show Exception, Clear Cache) 
- android.support.v7.widget.Toolbar (Open Class, Show Exception, Clear Cache) 
- android.support.v7.widget.AppCompatTextView (Open Class, Show Exception, Clear Cache) 
- android.support.v7.widget.ActionBarContextView (Open Class, Show Exception, Clear Cache) 
- android.support.v7.app.WindowDecorActionBar (Open Class, Show Exception, Clear Cache) 
- android.support.v7.widget.ActionBarOverlayLayout (Open Class, Show Exception, Clear Cache) 


Exception Details java.lang.ClassNotFoundException: android.support.v4.view.TintableBackgroundView 

我试图重建项目和手动刷新布局。但似乎没有任何工作。

那么我该怎么做?我使用过Android Studio 3.0金丝雀2科特林

编辑:

我已经取得了一些进展。我发现我的AppCompat主题都没有工作。

+0

我有相同的问题,您可以请粘贴gradle这个文件的内容?我尝试添加com.android.support,没有任何运气。谢谢 ! –

+1

任何其他人面临这个问题?我正在使用Canary build 5并面对此问题。 – Han

+0

渲染失败,出现已知错误。请尝试重建。以下类无法实例化: - android.support.v7.widget.AppCompatImageView(Open Class,Show Exception,Clear Cache) - android.support.v7.widget.ActionBarContainer(Open Class,Show Ex ... – thotheolh

回答

1

好了,请检查您的gradle这个,你增加了支持:程序兼容性依赖于应用程序/文件的build.gradle?同时程序兼容性:设计依赖

+0

已经加入他们两个。我这个问题与kotlin ?? –

+2

反正我现在添加com.android.support:support库也清理并重建我的项目,并以某种方式它的工作 –

+0

像@SidharthAnil说,我只是刚刚清理我的项目fo r Android Studio 3.1 canary 2,它工作。 –

2

我通过升级gradle这个插件版本3.0.0到-α-2和使用gradle这个包装gradle-4.0-milestone-1-all.zip解决的问题。

我登录Android的工作室问题跟踪器的问题 - https://issuetracker.google.com/u/1/issues/62251892

+0

但是从alpha2我得到即时运行错误...所以我现在禁用它。你知道任何解决方法? –

4

有与我支持库25.4.0版本的问题。我返回到版本25.3.1,并且布局渲染工作。

17

我也有这个问题,解决如下:修改appcompat-v7:26.0.0-beta2build.gradlemodle:app)到appcompat-v7:26.0.0-beta1

+1

这适用于我。我目前正在使用Android Studio 3.0 Canary 5. – nycdanie

+0

也适合我。 –

1

当我尝试自动填充时,我面临同样的问题。但 这将为我工作。请确保您添加这些依赖

compile "com.android.support:support-core-utils:26.0.0-beta2" 
compile "com.android.support:support-v4:26.0.0-beta2" 
compile "com.android.support:support-v13:26.0.0-beta2" 
compile "com.android.support:appcompat-v7:26.0.0-beta2" 
compile 'com.android.support:design:26.0.0-beta2' 

类路径 'com.android.tools.build:gradle:2.3.3'

57

该解决方案可以帮助你。 修改style.xml来自:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
</style> 

到:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"> 
</style> 
+2

你救了我一天 –

+0

为什么这个工作,一般来说这是一件坏事? – Thorinside

+0

谢谢,效果很好!从beta2更改为beta1并没有帮助我的基地。 – Ziem

5

误差 实行 'com.android.support:appcompat-v7:26.0.0-beta2' 变化 实行“COM .android.support:程序兼容性-V7:26.0.0-β1'

10

多德 我也有采用Android 3.0工作室, 同样的问题,我只是通过这样做的解决方案我在res的值文件夹下更改样式文件。

这是...

<!-- Base application theme. --> 
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

我已经加入 “基地”。在家长,使其正常工作!

2

如果没有上述工程的尝试:

  • 转到工具>安卓> SDK管理器
  • 内外观&行为>系统设置> Android SDK中选择SDK工具选项卡。
  • 将Android SDK构建工具更新为26.0.1或最新版本。

This答案很可能会解决问题。

1

我通过将支持设计版本更改为相同的appcompat版本来解决此问题。这是我的样品依赖

dependencies { 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.android.support:design:25.3.1' 
} 

以前我使用

compile 'com.android.support:design:25.4.0 

'