Страницы

Поиск по вопросам

суббота, 13 октября 2018 г.

selector c VectorDrawables падает на Resources$NotFoundException

Еще не так сильно запылилась новость, про возможность использования векторов в ресурсах, как 7 апреля вышло обновление для Android Studio и иже с ним. Обновление подсосало новую версию Gradle (2.0). В результате у меня приложение падает с воплями на Resources$NotFoundException на PRE-Lollipop версиях, но только на тех ресурсах, где вектор использовался в виде стейта в selector

Это кастомный чекбокс, ресурс устанавливаю программно через setButtonDrawable() и при запуске на PRE-Lollipop версиях получаю большой стейк на выходе. Если в setButtonDrawable() подать просто обычный вектор, то все прекрассно работает, за исключением того, что мне это не нужно, так как более нет стейтов на чебкоксе. Естественно для работы в векторами в gradle файле я указывал необходимые параметры. С начало по стейку грешил на сам векторный файл, но при установке ресурса ic_like_stroke_24dp на прямую в виджет, креш не вызывается. Вот сами векторы для экспериментов.
ic_like_stroke_24dp.xml



и
ic_like_solid_red_24dp


До того, как я обновился у меня в gradle были следующие параметры (для Gradle 1.5)
android { defaultConfig { generatedDensities = [] } aaptOptions { additionalParameters "--no-version-vectors" } }
После обновления Android Studio и Gradle (2.0) я заменил выше описанное на
android { defaultConfig { vectorDrawables.useSupportLibrary = true } }
И отсюда вопрос, куда копать? После обновления ушла возможность использовать вектор в selector. Откатить студию до прошлой версии можно, но не выход. Стейк:
Fatal Exception: android.content.res.Resources$NotFoundException: File res/drawable/check_box_like.xml from drawable resource ID #0x7f02004d at android.content.res.Resources.loadDrawable(Resources.java:1953) at android.content.res.Resources.getDrawable(Resources.java:660) at android.support.v7.widget.ResourcesWrapper.getDrawable(ResourcesWrapper.java:128) at android.support.v7.widget.TintResources.getDrawable(TintResources.java:45) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:201) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191) at android.support.v7.widget.AppCompatCheckBox.setButtonDrawable(AppCompatCheckBox.java:74) at view.catalogs.CatalogListAdapter$ViewHolder.(CatalogListAdapter.java:126) at view.catalogs.CatalogListAdapter.getItemView(CatalogListAdapter.java:61) at com.culiu.mhvp.core.tabs.GridViewWithHeaderBaseAdapter.createItemRow(GridViewWithHeaderBaseAdapter.java:114) at com.culiu.mhvp.core.tabs.GridViewWithHeaderBaseAdapter.getView(GridViewWithHeaderBaseAdapter.java:95) at com.culiu.mhvp.core.InnerListView$InflateFirstItemIfNeededAdapter.getView(InnerListView.java:557) at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220) at android.widget.AbsListView.obtainView(AbsListView.java:2159) at android.widget.ListView.makeAndAddView(ListView.java:1831) at android.widget.ListView.fillDown(ListView.java:674) at android.widget.ListView.fillSpecific(ListView.java:1332) at android.widget.ListView.layoutChildren(ListView.java:1642) at android.widget.AbsListView.onLayout(AbsListView.java:1994) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1695) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1695) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1091) at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:801) at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:815) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1187) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) at android.view.Choreographer.doCallbacks(Choreographer.java:562) at android.view.Choreographer.doFrame(Choreographer.java:532) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(NativeStart.java) Caused by android.content.res.Resources$NotFoundException: File res/drawable/ic_like_stroke_24dp.xml from drawable resource ID #0x7f02009d at android.content.res.Resources.loadDrawable(Resources.java:1953) at android.content.res.Resources.getDrawable(Resources.java:660) at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173) at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:885) at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822) at android.content.res.Resources.loadDrawable(Resources.java:1950) at android.content.res.Resources.getDrawable(Resources.java:660) at android.support.v7.widget.ResourcesWrapper.getDrawable(ResourcesWrapper.java:128) at android.support.v7.widget.TintResources.getDrawable(TintResources.java:45) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:201) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191) at android.support.v7.widget.AppCompatCheckBox.setButtonDrawable(AppCompatCheckBox.java:74) at view.catalogs.CatalogListAdapter$ViewHolder.(CatalogListAdapter.java:126) at view.catalogs.CatalogListAdapter.getItemView(CatalogListAdapter.java:61) at com.culiu.mhvp.core.tabs.GridViewWithHeaderBaseAdapter.createItemRow(GridViewWithHeaderBaseAdapter.java:114) at com.culiu.mhvp.core.tabs.GridViewWithHeaderBaseAdapter.getView(GridViewWithHeaderBaseAdapter.java:95) at com.culiu.mhvp.core.InnerListView$InflateFirstItemIfNeededAdapter.getView(InnerListView.java:557) at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220) at android.widget.AbsListView.obtainView(AbsListView.java:2159) at android.widget.ListView.makeAndAddView(ListView.java:1831) at android.widget.ListView.fillDown(ListView.java:674) at android.widget.ListView.fillSpecific(ListView.java:1332) at android.widget.ListView.layoutChildren(ListView.java:1642) at android.widget.AbsListView.onLayout(AbsListView.java:1994) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1695) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1695) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1091) at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:801) at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:815) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1187) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) at android.view.Choreographer.doCallbacks(Choreographer.java:562) at android.view.Choreographer.doFrame(Choreographer.java:532) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(NativeStart.java) Caused by org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag vector at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881) at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822) at android.content.res.Resources.loadDrawable(Resources.java:1950) at android.content.res.Resources.getDrawable(Resources.java:660) at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173) at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:885) at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822) at android.content.res.Resources.loadDrawable(Resources.java:1950) at android.content.res.Resources.getDrawable(Resources.java:660) at android.support.v7.widget.ResourcesWrapper.getDrawable(ResourcesWrapper.java:128) at android.support.v7.widget.TintResources.getDrawable(TintResources.java:45) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:201) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191) at android.support.v7.widget.AppCompatCheckBox.setButtonDrawable(AppCompatCheckBox.java:74) at view.catalogs.CatalogListAdapter$ViewHolder.(CatalogListAdapter.java:126) at view.catalogs.CatalogListAdapter.getItemView(CatalogListAdapter.java:61) at com.culiu.mhvp.core.tabs.GridViewWithHeaderBaseAdapter.createItemRow(GridViewWithHeaderBaseAdapter.java:114) at com.culiu.mhvp.core.tabs.GridViewWithHeaderBaseAdapter.getView(GridViewWithHeaderBaseAdapter.java:95) at com.culiu.mhvp.core.InnerListView$InflateFirstItemIfNeededAdapter.getView(InnerListView.java:557) at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220) at android.widget.AbsListView.obtainView(AbsListView.java:2159) at android.widget.ListView.makeAndAddView(ListView.java:1831) at android.widget.ListView.fillDown(ListView.java:674) at android.widget.ListView.fillSpecific(ListView.java:1332) at android.widget.ListView.layoutChildren(ListView.java:1642) at android.widget.AbsListView.onLayout(AbsListView.java:1994) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1695) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1695) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1091) at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:801) at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:815) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1187) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.widget.FrameLayout.onLayout(FrameLayout.java:448) at android.view.View.layout(View.java:14008) at android.view.ViewGroup.layout(ViewGroup.java:4373) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) at android.view.Choreographer.doCallbacks(Choreographer.java:562) at android.view.Choreographer.doFrame(Choreographer.java:532) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(NativeStart.java)


Ответ

Нарвался на новость - https://plus.google.com/+AndroidDevelopers/posts/iTDmFiGrVne частично на время пока можно забыть про векторы. Проблема решается удалением строки в gradle
android { defaultConfig { vectorDrawables.useSupportLibrary = true } }
Это приведет к увеличению объему апк, за счет конвертации векторов в png.

Комментариев нет:

Отправить комментарий