使用支持库时android.support.v7.widget.Toolbar VectorDrawableCompat IllegalStateException 24+ [英] android.support.v7.widget.Toolbar VectorDrawableCompat IllegalStateException when using support lib 24+

查看:148
本文介绍了使用支持库时android.support.v7.widget.Toolbar VectorDrawableCompat IllegalStateException 24+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Android Studio中启动了一个新项目,并配置了gradle构建设置.当我将android.support.v7.widget.Toolbar添加到布局中时,在设计视图中出现以下错误.请注意,仅当使用小于21的API(特别是API 16-19)进行预览时,才会显示此错误.当我使用API​​ 21-24进行预览时,一切正常.

I've started a new project in Android Studio and configured my gradle build settings. When I add an android.support.v7.widget.Toolbar to a layout, I get the following error when in design view. Keep note that this error only shows up when previewing with an API less than 21 (specifically APIs 16 - 19). Everything works fine when I preview with API 21 - 24.

我查看了许多解决方案并尝试了它们,但没有一个解决了问题.我尝试做的一件事是将其添加到我的gradle中:

I have looked at a number of solutions and tried them, but none have solved the issue. One thing I tried doing was adding this to my gradle:

vectorDrawables.useSupportLibrary = true  

但这并不能解决问题.我尝试将自己的已编译的SdkVersion配置为23,将buildToolsVersion配置为23.0.3.这并没有改变任何东西.如果我将支持库版本更改为23.4.0或更低版本,则此问题已解决.一旦将其更改回24.0.0或更高版本,它就会返回.

But that didn't solve the issue. I tried configuring my compiledSdkVersion to 23, buildToolsVersion to 23.0.3. This did not change anything. If I change the support library versions to 23.4.0 or below, then the issue is resolved. As soon as I change it back up to 24.0.0 or higher then it returns.

清除缓存,清理项目并重建,并使缓存无效并重新启动并不能解决问题.

Clearing the cache, cleaning the project and rebuilding, and invalidating the cache and restarting did not solve the issue.

The following classes could not be instantiated:
- android.support.v7.widget.Toolbar (Open Class, Show Exception, Clear Cache)

Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when in the IDE

Exception Details
java.lang.IllegalStateException: This app has been built with an incorrect configuration.
Please configure your build for VectorDrawableCompat.
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:692)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:181)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:67)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:298)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:229)
...

invalid drawable tag vector

这是我的应用程序build.gradle:

Here is my app build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1" // https://developer.android.com/studio/releases/build-tools.html

    defaultConfig {
        applicationId "org.path.path"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 0
        versionName "0.0.0"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    ext {
        supportLibVersion = '24.0.0' // https://developer.android.com/topic/libraries/support-library/revisions.html
    }

    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile "com.android.support:appcompat-v7:${supportLibVersion}"
    compile "com.android.support:design:${supportLibVersion}"
    compile "com.android.support:cardview-v7:${supportLibVersion}"
    compile "com.android.support:recyclerview-v7:${supportLibVersion}"
}

我的项目build.gradle使用的是classpath 'com.android.tools.build:gradle:2.1.2'

My project build.gradle is using classpath 'com.android.tools.build:gradle:2.1.2'

这是工具栏xml:

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:minHeight="?attr/actionBarSize"
android:elevation="4dp"
android:background="@color/colorPrimary"
app:theme="@style/ActionBarThemeOverlay"
app:popupTheme="@style/ActionBarPopupThemeOverlay"/>

最后是我的styles.xml:

And finally, my styles.xml:

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

<!-- ActionBar -->
<style name="ActionBarPopupThemeOverlay" parent="ThemeOverlay.AppCompat.Dark" />
<style name="ActionBarThemeOverlay" parent="ThemeOverlay.AppCompat.Dark">
    <item name="android:textColorPrimary">@color/text_on_primary</item>
    <item name="android:textColorSecondary">@color/subtitle_on_primary</item>
</style>

这是一个错误,还是我不能使用支持库24或更高版本?我不知道有任何其他配置需要更改,因为该异常试图引导.

Is this a bug, or am I just not able to use the support library versions 24 or higher? I'm not aware of any other configurations to change as the exception tried to direct.

推荐答案

检查此问题:

appcompat-v7 24.0.0与栅格化矢量不兼容

这篇关于使用支持库时android.support.v7.widget.Toolbar VectorDrawableCompat IllegalStateException 24+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆