26

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"

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

EDITED:

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

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Sidharth Anil
  • 768
  • 1
  • 6
  • 14
  • I have the exact same issue, could you please paste the content of your gradle file ? I tried addding the com.android.support, without any luck. Thank you ! – Alexandre G. May 31 '17 at 14:50
  • 1
    Anyone else facing this issue? I'm using Canary build 5 and faced this. – Han Jul 04 '17 at 07:21
  • Rendering failed with a known bug. Please try a rebuild. 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 Ex... – thotheolh Jul 04 '17 at 08:34
  • The above running on 26.0.0-beta2 and throws rendering errors in Android Studio. – thotheolh Jul 04 '17 at 08:43
  • 1
    @Han - Chen chen's answer below solves this problem. – nycdanie Jul 05 '17 at 16:32
  • somebody reported it here https://issuetracker.google.com/issues/63054597 – Ajay S Jul 11 '17 at 06:43
  • Refer this link once, https://stackoverflow.com/a/45238691/4862479 – Kailas Bhakade Jul 26 '17 at 07:03
  • Possible duplicate of [Android Studio rendering problems](https://stackoverflow.com/questions/18195807/android-studio-rendering-problems) – Shayan Aug 20 '18 at 08:13

11 Answers11

93

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

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

to:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
</style>
Zhong W
  • 933
  • 5
  • 5
18

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.

fthiella
  • 48,073
  • 15
  • 90
  • 106
oreo
  • 213
  • 1
  • 11
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.

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!

7

error is :

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

change :

implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49
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.

Vanama
  • 507
  • 1
  • 7
  • 15
4

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

Environment I was working on:
Android Studio 3.0.1

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

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:

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

Community
  • 1
  • 1
Randika Vishman
  • 7,983
  • 3
  • 57
  • 80
2

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

MrCurious
  • 150
  • 3
  • 11
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.

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

2

If none of the above works the try this:

  • Go to Tools > Android > SDK Manager
  • Inside Appearance & Behavior > System Settings > Android SDK select the SDK Tools tab.
  • update the Android SDK Build-Tools to 26.0.1 or the latest available.

This answer will most probably solve the issue.

Darush
  • 11,403
  • 9
  • 62
  • 60
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'                  
Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49
Black_Dreams
  • 572
  • 1
  • 5
  • 11
1

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

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

'

Pajri Aprilio
  • 322
  • 5
  • 16