android.support.graphics.drawable.VectorDrawableCompat不仅适用于API 21

时间:2016-06-27 07:19:19

标签: android android-activity android-vectordrawable

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.access$800(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)

2 个答案:

答案 0 :(得分:2)

首先将依赖项更改为

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'

并在使用向量的活动中使用此代码。

static { AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); }

答案 1 :(得分:0)

只需在build.gradle中添加以下依赖项。这将解决您的问题。我使用 25.0.2 buildToolsVersion。

compile 'com.android.support:support-vector-drawable:25.3.0'