在the official document之后,有一个应用通过向build.gradle添加以下内容来支持棒棒糖之前的设备的矢量可绘制对象:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
一切似乎都可以正常工作,直到它开始具有如下所示的旋转可绘制矢量:
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="180"
android:toDegrees="0"
android:drawable="@drawable/ic_screen_lock_landscape_white_24dp">
</rotate>
它在棒棒糖之前的设备上开始generate crashes。崩溃在vectorDrawables.useSupportLibrary = true was removed之后停止。所有矢量可绘制对象似乎在棒棒糖之前的设备上都能正常工作。换句话说,对于向后兼容,vectorDrawables.useSupportLibrary = true似乎是多余的。谁能对此有所启发?
以下是崩溃的示例:
android.content.res.Resources$NotFoundException:
at android.content.res.Resources.loadDrawable (Resources.java:2096)
at android.content.res.Resources.getDrawable (Resources.java:700)
at android.support.v4.content.ContextCompat.getDrawable (ContextCompat.java:465)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable (AppCompatDrawableManager.java:203)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable (AppCompatDrawableManager.java:191)
at android.support.v7.content.res.AppCompatResources.getDrawable (AppCompatResources.java:102)
at android.support.v7.view.menu.MenuItemImpl.getIcon (MenuItemImpl.java:505)
at android.support.design.internal.NavigationMenuItemView.initialize (NavigationMenuItemView.java:114)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onBindViewHolder (NavigationMenuPresenter.java:442)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onViewRecycled (NavigationMenuPresenter.java:361)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onBindViewHolder (NavigationMenuPresenter.java:361)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder (RecyclerView.java:6781)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder (RecyclerView.java:6823)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline (RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline (RecyclerView.java:6019)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5858)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5854)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next (LinearLayoutManager.java:2230)
at android.support.v7.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1557)
at android.support.v7.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1517)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren (LinearLayoutManager.java:612)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2 (RecyclerView.java:3924)
at android.support.v7.widget.RecyclerView.onMeasure (RecyclerView.java:3336)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at android.support.design.widget.NavigationView.onMeasure (NavigationView.java:245)
at android.view.View.measure (View.java:16497)
at android.support.v4.widget.DrawerLayout.onMeasure (DrawerLayout.java:1148)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at android.support.v7.widget.ContentFrameLayout.onMeasure (ContentFrameLayout.java:143)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical (LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure (LinearLayout.java:588)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical (LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure (LinearLayout.java:588)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure (PhoneWindow.java:2293)
at android.view.View.measure (View.java:16497)
at android.view.ViewRootImpl.performMeasure (ViewRootImpl.java:1918)
at android.view.ViewRootImpl.measureHierarchy (ViewRootImpl.java:1113)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:1295)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:5672)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:772)
at android.view.Choreographer.doCallbacks (Choreographer.java:585)
at android.view.Choreographer.doFrame (Choreographer.java:555)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:758)
at android.os.Handler.handleCallback (Handler.java:733)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:136)
at android.app.ActivityThread.main (ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative (Method.java)
at java.lang.reflect.Method.invoke (Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:788)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:604)
at dalvik.system.NativeStart.main (NativeStart.java)
Caused by: android.content.res.Resources$NotFoundException:
at android.content.res.Resources.loadDrawable (Resources.java:2096)
at android.content.res.Resources.getDrawable (Resources.java:700)
at android.graphics.drawable.RotateDrawable.inflate (RotateDrawable.java:247)
at android.graphics.drawable.Drawable.createFromXmlInner (Drawable.java:937)
at android.graphics.drawable.Drawable.createFromXml (Drawable.java:877)
at android.content.res.Resources.loadDrawable (Resources.java:2092)
at android.content.res.Resources.getDrawable (Resources.java:700)
at android.support.v4.content.ContextCompat.getDrawable (ContextCompat.java:465)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable (AppCompatDrawableManager.java:203)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable (AppCompatDrawableManager.java:191)
at android.support.v7.content.res.AppCompatResources.getDrawable (AppCompatResources.java:102)
at android.support.v7.view.menu.MenuItemImpl.getIcon (MenuItemImpl.java:505)
at android.support.design.internal.NavigationMenuItemView.initialize (NavigationMenuItemView.java:114)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onBindViewHolder (NavigationMenuPresenter.java:442)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onViewRecycled (NavigationMenuPresenter.java:361)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onBindViewHolder (NavigationMenuPresenter.java:361)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder (RecyclerView.java:6781)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder (RecyclerView.java:6823)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline (RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline (RecyclerView.java:6019)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5858)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5854)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next (LinearLayoutManager.java:2230)
at android.support.v7.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1557)
at android.support.v7.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1517)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren (LinearLayoutManager.java:612)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2 (RecyclerView.java:3924)
at android.support.v7.widget.RecyclerView.onMeasure (RecyclerView.java:3336)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at android.support.design.widget.NavigationView.onMeasure (NavigationView.java:245)
at android.view.View.measure (View.java:16497)
at android.support.v4.widget.DrawerLayout.onMeasure (DrawerLayout.java:1148)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at android.support.v7.widget.ContentFrameLayout.onMeasure (ContentFrameLayout.java:143)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical (LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure (LinearLayout.java:588)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical (LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure (LinearLayout.java:588)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure (PhoneWindow.java:2293)
at android.view.View.measure (View.java:16497)
at android.view.ViewRootImpl.performMeasure (ViewRootImpl.java:1918)
at android.view.ViewRootImpl.measureHierarchy (ViewRootImpl.java:1113)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:1295)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:5672)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:772)
at android.view.Choreographer.doCallbacks (Choreographer.java:585)
at android.view.Choreographer.doFrame (Choreographer.java:555)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:758)
at android.os.Handler.handleCallback (Handler.java:733)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:136)
at android.app.ActivityThread.main (ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative (Method.java)
at java.lang.reflect.Method.invoke (Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:788)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:604)
at dalvik.system.NativeStart.main (NativeStart.java)
Caused by: org.xmlpull.v1.XmlPullParserException:
at android.graphics.drawable.Drawable.createFromXmlInner (Drawable.java:933)
at android.graphics.drawable.Drawable.createFromXml (Drawable.java:877)
at android.content.res.Resources.loadDrawable (Resources.java:2092)
at android.content.res.Resources.getDrawable (Resources.java:700)
at android.graphics.drawable.RotateDrawable.inflate (RotateDrawable.java:247)
at android.graphics.drawable.Drawable.createFromXmlInner (Drawable.java:937)
at android.graphics.drawable.Drawable.createFromXml (Drawable.java:877)
at android.content.res.Resources.loadDrawable (Resources.java:2092)
at android.content.res.Resources.getDrawable (Resources.java:700)
at android.support.v4.content.ContextCompat.getDrawable (ContextCompat.java:465)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable (AppCompatDrawableManager.java:203)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable (AppCompatDrawableManager.java:191)
at android.support.v7.content.res.AppCompatResources.getDrawable (AppCompatResources.java:102)
at android.support.v7.view.menu.MenuItemImpl.getIcon (MenuItemImpl.java:505)
at android.support.design.internal.NavigationMenuItemView.initialize (NavigationMenuItemView.java:114)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onBindViewHolder (NavigationMenuPresenter.java:442)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onViewRecycled (NavigationMenuPresenter.java:361)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onBindViewHolder (NavigationMenuPresenter.java:361)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder (RecyclerView.java:6781)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder (RecyclerView.java:6823)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline (RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline (RecyclerView.java:6019)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5858)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5854)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next (LinearLayoutManager.java:2230)
at android.support.v7.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1557)
at android.support.v7.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1517)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren (LinearLayoutManager.java:612)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2 (RecyclerView.java:3924)
at android.support.v7.widget.RecyclerView.onMeasure (RecyclerView.java:3336)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at android.support.design.widget.NavigationView.onMeasure (NavigationView.java:245)
at android.view.View.measure (View.java:16497)
at android.support.v4.widget.DrawerLayout.onMeasure (DrawerLayout.java:1148)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at android.support.v7.widget.ContentFrameLayout.onMeasure (ContentFrameLayout.java:143)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical (LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure (LinearLayout.java:588)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical (LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure (LinearLayout.java:588)
at android.view.View.measure (View.java:16497)
at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure (PhoneWindow.java:2293)
at android.view.View.measure (View.java:16497)
at android.view.ViewRootImpl.performMeasure (ViewRootImpl.java:1918)
at android.view.ViewRootImpl.measureHierarchy (ViewRootImpl.java:1113)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:1295)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:5672)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:772)
at android.view.Choreographer.doCallbacks (Choreographer.java:585)
at android.view.Choreographer.doFrame (Choreographer.java:555)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:758)
at android.os.Handler.handleCallback (Handler.java:733)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:136)
at android.app.ActivityThread.main (ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative (Method.java)
at java.lang.reflect.Method.invoke (Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:788)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:604)
at dalvik.system.NativeStart.main (NativeStart.java)