android.support.graphics.drawable.VectorDrawableCompat 不适用于 API 21
android.support.graphics.drawable.VectorDrawableCompat not working only on API 21
java.lang.NoClassDefFoundError: android.support.graphics.drawable.VectorDrawableCompat
at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:891)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:356)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.app.AppCompatDelegateImplBase$ActionBarDrawableToggleImpl.getThemeUpIndicator(AppCompatDelegateImplBase.java:146)
at android.support.v7.app.ActionBarDrawerToggle.getThemeUpIndicator(ActionBarDrawerToggle.java:466)
at android.support.v7.app.ActionBarDrawerToggle.<init>(ActionBarDrawerToggle.java:226)
at android.support.v7.app.ActionBarDrawerToggle.<init>(ActionBarDrawerToggle.java:181)
at onCreate(MainActivity.java:88)
at Dashboard.onCreate(Dashboard.java:51)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access0(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
首先把依赖改成
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
并在使用向量的 activity 中使用此代码。
static
{
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
只需在 build.gradle 中添加以下依赖项。这将解决您的问题。我正在使用 25.0.2 buildToolsVersion.
compile 'com.android.support:support-vector-drawable:25.3.0'
java.lang.NoClassDefFoundError: android.support.graphics.drawable.VectorDrawableCompat
at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:891)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:356)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.app.AppCompatDelegateImplBase$ActionBarDrawableToggleImpl.getThemeUpIndicator(AppCompatDelegateImplBase.java:146)
at android.support.v7.app.ActionBarDrawerToggle.getThemeUpIndicator(ActionBarDrawerToggle.java:466)
at android.support.v7.app.ActionBarDrawerToggle.<init>(ActionBarDrawerToggle.java:226)
at android.support.v7.app.ActionBarDrawerToggle.<init>(ActionBarDrawerToggle.java:181)
at onCreate(MainActivity.java:88)
at Dashboard.onCreate(Dashboard.java:51)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access0(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
首先把依赖改成
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
并在使用向量的 activity 中使用此代码。
static
{
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
只需在 build.gradle 中添加以下依赖项。这将解决您的问题。我正在使用 25.0.2 buildToolsVersion.
compile 'com.android.support:support-vector-drawable:25.3.0'