Render error in Android Studio 3.0 Layout Editor

Viewed 35352

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.

11 Answers

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.

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

'

Related