在Android Studio 3.0布局编辑器中渲染错误

时间:2021-01-16 20:56:46

I just started learning Kotlin for android development and started an empty project and added an activity. I have added the required gradle dependencies as said in Kotlin docs. By default the xml file of MainActivity contains only a TextView. But when I try to preview the xml in Layout Editor it shows a "Render Error"

我刚刚开始学习Kotlin进行android开发,并开始了一个空项目并添加了一个活动。我已经在Kotlin文档中添加了所需的gradle依赖项。默认情况下,MainActivity的xml文件仅包含TextView。但是当我尝试在布局编辑器中预览xml时,它会显示“渲染错误”

Render problem

Failed to load AppCompat ActionBar with unknown error.

Also I'm getting this

我也得到了这个

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

I have tried rebuilding the project and refreshing layout manually. But nothing seems to work.

我尝试过重建项目并手动刷新布局。但似乎没有任何效果。

So what do I do? I'm using Android Studio 3.0 Canary 2 with Kotlin

那我该怎么办?我正在使用带有Kotlin的Android Studio 3.0 Canary 2

EDITED:

I have made some progress. I have found that none of my AppCompat Themes are working.

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

11 个解决方案

#1


1  

Well, check your gradle , have you added support:appcompat dependency in app/build.gradle file ? also appcompat:design dependency

好吧,检查你的gradle,你是否添加了支持:app / build.gradle文件中的appcompat依赖? appcompat:设计依赖

#2


84  

This solution may help you. Modify style.xml from:

这个解决方案可以帮到你。修改style.xml:

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

to:

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

#3


17  

I also have this problem, solved as follows: modify the appcompat-v7:26.0.0-beta2 on build.gradle (modle:app) to appcompat-v7:26.0.0-beta1.

我也遇到了这个问题,解决方法如下:将build.atdle(modle:app)上的appcompat-v7:26.0.0-beta2修改为appcompat-v7:26.0.0-beta1。

#4


12  

Dude I'm also having same issue using Android Studio 3.0, I got an solution by just make some changes in style file under the value folder of res.

Dude我也有使用Android Studio 3.0的相同问题,我只需在res文件夹下的样式文件中进行一些更改即可获得解决方案。

Here it is...

这里是...

<!-- 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>

I have added "Base." in parent to make it work properly!

我添加了“Base”。在父母,使其正常工作!

#5


6  

error is :

错误是:

implementation 'com.android.support:appcompat-v7:26.0.0-beta2' 

change :

implementation 'com.android.support:appcompat-v7:26.0.0-beta1'

#6


4  

There is problem with version 25.4.0 of support libraries by me. I returned to version 25.3.1 and the layout render works.

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

#7


3  

rendering failed in Android Studio android.support.v7.widget.AppCompatImageView

Environment I was working on:
Android Studio 3.0.1

我正在研究的环境:Android Studio 3.0.1

Cause was found to be in app/build.gradle file:

发现原因在app / build.gradle文件中:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24           -----> 1
    buildToolsVersion "24.0.0"     -----> 2

    defaultConfig {
        applicationId "com.example.some_project"
        minSdkVersion 15
        targetSdkVersion 24        -----> 3
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:24.0.0'        -----> 4
}

I changed some of the respective lines to be as follows:

我改变了一些相应的行如下:

compileSdkVersion 26                       <------------ 1
buildToolsVersion "26.0.3"                 <------------ 2

targetSdkVersion 26                        <------------ 3

compile 'com.android.support:appcompat-v7:26.1.0'  <---- 4

And I didn't need to change anything in the styles.xml file. Most of the answers above had suggested to change following line:

而且我不需要在styles.xml文件中更改任何内容。上面的大多数答案都建议更改以下行:

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

into following:

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

But I didn't want to do it. It seems like that, Google Android has moved the Theme(s) API from Base package to a more root package, when they have upgraded the API.

但我不想这样做。看起来,谷歌Android已经将主题API从Base包移动到更多根包,当他们升级了API时。

#8


2  

I solved the issue by upgrading the gradle plugin version to 3.0.0-alpha2 and using gradle wrapper gradle-4.0-milestone-1-all.zip.

我通过将gradle插件版本升级到3.0.0-alpha2并使用gradle wrapper gradle-4.0-milestone-1-all.zip解决了这个问题。

I logged the issue in android studio issue tracker - https://issuetracker.google.com/u/1/issues/62251892

我在android studio问题跟踪器中记录了这个问题 - https://issuetracker.google.com/u/1/issues/62251892

#9


2  

If none of the above works the try this:

如果以上都不起作用,请尝试以下方法:

  • Go to Tools > Android > SDK Manager
  • 转到工具> Android> SDK管理器

  • Inside Appearance & Behavior > System Settings > Android SDK select the SDK Tools tab.
  • 内部和行为>系统设置> Android SDK选择SDK工具选项卡。

  • update the Android SDK Build-Tools to 26.0.1 or the latest available.
  • 将Android SDK Build-Tools更新为26.0.1或最新版本。

This answer will most probably solve the issue.

这个答案很可能会解决这个问题。

#10


1  

I solved this issue by change the support design version to the same appcompat version. This is my sample dependencies

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

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

Previously i used

以前我用过

compile 'com.android.support:design:25.4.0

'

#11


1  

I'm facing same issue when i tried autofill. but This will working for me. Make sure you add these dependencies:

当我尝试自动填充时,我面临同样的问题。但这对我有用。确保添加这些依赖项:

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'

and

classpath 'com.android.tools.build:gradle:2.3.3'                  

#1


1  

Well, check your gradle , have you added support:appcompat dependency in app/build.gradle file ? also appcompat:design dependency

好吧,检查你的gradle,你是否添加了支持:app / build.gradle文件中的appcompat依赖? appcompat:设计依赖

#2


84  

This solution may help you. Modify style.xml from:

这个解决方案可以帮到你。修改style.xml:

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

to:

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

#3


17  

I also have this problem, solved as follows: modify the appcompat-v7:26.0.0-beta2 on build.gradle (modle:app) to appcompat-v7:26.0.0-beta1.

我也遇到了这个问题,解决方法如下:将build.atdle(modle:app)上的appcompat-v7:26.0.0-beta2修改为appcompat-v7:26.0.0-beta1。

#4


12  

Dude I'm also having same issue using Android Studio 3.0, I got an solution by just make some changes in style file under the value folder of res.

Dude我也有使用Android Studio 3.0的相同问题,我只需在res文件夹下的样式文件中进行一些更改即可获得解决方案。

Here it is...

这里是...

<!-- 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>

I have added "Base." in parent to make it work properly!

我添加了“Base”。在父母,使其正常工作!

#5


6  

error is :

错误是:

implementation 'com.android.support:appcompat-v7:26.0.0-beta2' 

change :

implementation 'com.android.support:appcompat-v7:26.0.0-beta1'

#6


4  

There is problem with version 25.4.0 of support libraries by me. I returned to version 25.3.1 and the layout render works.

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

#7


3  

rendering failed in Android Studio android.support.v7.widget.AppCompatImageView

Environment I was working on:
Android Studio 3.0.1

我正在研究的环境:Android Studio 3.0.1

Cause was found to be in app/build.gradle file:

发现原因在app / build.gradle文件中:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24           -----> 1
    buildToolsVersion "24.0.0"     -----> 2

    defaultConfig {
        applicationId "com.example.some_project"
        minSdkVersion 15
        targetSdkVersion 24        -----> 3
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:24.0.0'        -----> 4
}

I changed some of the respective lines to be as follows:

我改变了一些相应的行如下:

compileSdkVersion 26                       <------------ 1
buildToolsVersion "26.0.3"                 <------------ 2

targetSdkVersion 26                        <------------ 3

compile 'com.android.support:appcompat-v7:26.1.0'  <---- 4

And I didn't need to change anything in the styles.xml file. Most of the answers above had suggested to change following line:

而且我不需要在styles.xml文件中更改任何内容。上面的大多数答案都建议更改以下行:

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

into following:

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

But I didn't want to do it. It seems like that, Google Android has moved the Theme(s) API from Base package to a more root package, when they have upgraded the API.

但我不想这样做。看起来,谷歌Android已经将主题API从Base包移动到更多根包,当他们升级了API时。

#8


2  

I solved the issue by upgrading the gradle plugin version to 3.0.0-alpha2 and using gradle wrapper gradle-4.0-milestone-1-all.zip.

我通过将gradle插件版本升级到3.0.0-alpha2并使用gradle wrapper gradle-4.0-milestone-1-all.zip解决了这个问题。

I logged the issue in android studio issue tracker - https://issuetracker.google.com/u/1/issues/62251892

我在android studio问题跟踪器中记录了这个问题 - https://issuetracker.google.com/u/1/issues/62251892

#9


2  

If none of the above works the try this:

如果以上都不起作用,请尝试以下方法:

  • Go to Tools > Android > SDK Manager
  • 转到工具> Android> SDK管理器

  • Inside Appearance & Behavior > System Settings > Android SDK select the SDK Tools tab.
  • 内部和行为>系统设置> Android SDK选择SDK工具选项卡。

  • update the Android SDK Build-Tools to 26.0.1 or the latest available.
  • 将Android SDK Build-Tools更新为26.0.1或最新版本。

This answer will most probably solve the issue.

这个答案很可能会解决这个问题。

#10


1  

I solved this issue by change the support design version to the same appcompat version. This is my sample dependencies

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

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

Previously i used

以前我用过

compile 'com.android.support:design:25.4.0

'

#11


1  

I'm facing same issue when i tried autofill. but This will working for me. Make sure you add these dependencies:

当我尝试自动填充时,我面临同样的问题。但这对我有用。确保添加这些依赖项:

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'

and

classpath 'com.android.tools.build:gradle:2.3.3'