a-student / bettervectordrawable Goto Github PK
View Code? Open in Web Editor NEWThe VectorDrawable implementation for Android 4.0+
The VectorDrawable implementation for Android 4.0+
Hey thanks for this Compat library, however I am getting an error when I try to use the vector assets as drawables outside of an XML file.
I am using 0.8 of the BetterVectorDrawable library
generatedDensities = []
version 23.1.1 of appcompat-v7
Compiling with SDK-23
Running on a 4.4.4 Moto G 1st gen
If I don't specifically try to use a drawable I get this in the log
02-03 12:56:11.322 21317-21317/? I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method com.bettervectordrawable.VectorDrawableCompat.inflate
02-03 12:56:11.322 21317-21317/? W/dalvikvm: VFY: unable to resolve virtual method 493: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
02-03 12:56:11.322 21317-21317/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0023
02-03 12:56:11.343 21317-21317/? W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
02-03 12:56:11.343 21317-21317/? I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
02-03 12:56:11.343 21317-21317/? W/dalvikvm: VFY: unable to resolve interface method 16781: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
02-03 12:56:11.343 21317-21317/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
02-03 12:56:11.343 21317-21317/? I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
02-03 12:56:11.344 21317-21317/? W/dalvikvm: VFY: unable to resolve interface method 16785: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
02-03 12:56:11.344 21317-21317/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
This repeats quite a bit
02-03 12:56:11.417 21317-21317/? W/ReflectionHelper: Unable to find method PorterDuffColorFilter.setMode
java.lang.NoSuchMethodException: setMode [class android.graphics.PorterDuff$Mode]
at java.lang.Class.getConstructorOrMethod(Class.java:472)
at java.lang.Class.getDeclaredMethod(Class.java:640)
at com.bettervectordrawable.utils.ReflectionHelper.tryFindMethod(ReflectionHelper.java:20)
at com.bettervectordrawable.lib.graphics.drawable.DrawableExtension.(DrawableExtension.java:23)
at com.bettervectordrawable.lib.graphics.drawable.VectorDrawable$VectorDrawableState.(VectorDrawable.java:697)
at com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.(VectorDrawable.java:233)
at com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.(VectorDrawable.java:229)
at com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.create(VectorDrawable.java:497)
at com.bettervectordrawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:115)
at com.bettervectordrawable.VectorDrawableFactory.get(VectorDrawableFactory.java:36)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:31)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:22)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:10)
at android.content.res.Resources.loadDrawable(Resources.java:2060)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.(View.java:3572)
at android.widget.TextView.(TextView.java:623)
at android.widget.Button.(Button.java:107)
at android.widget.Button.(Button.java:103)
at basewidgets.FontButton.(FontButton.java:18)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.myclass.myfragment.onCreateView(myfragment.kt:47)
at android.app.Fragment.performCreateView(Fragment.java:1700)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
at android.app.BackStackRecord.run(BackStackRecord.java:684)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
at android.app.Activity.performStart(Activity.java:5257)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
02-03 12:56:11.418 21317-21317/? I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method com.bettervectordrawable.lib.content.res.TypedArrayExtension.getChangingConfigurations
02-03 12:56:11.418 21317-21317/? W/dalvikvm: VFY: unable to resolve virtual method 530: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
02-03 12:56:11.418 21317-21317/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
Sorry, I created issue because I can't find your email.
You wrote: "The VectorDrawable implementation for Android 4.0+ (API level 14 or greater).".
But when I compiled my application with BetterVectorDrawable for API level 10, it still works. Probably because I'm using AppCompat.
Are there any parts of BetterVectorDrawable that will not work under API level 10 ?
E/VectorDrawable: parser error
org.xmlpull.v1.XmlPullParserException: Binary XML file line #2 tag requires viewportWidth > 0
at com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.updateStateFromTypedArray(VectorDrawable.java:556)
at com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:520)
at com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:531)
at com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.create(VectorDrawable.java:498)
at com.bettervectordrawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:115)
at com.bettervectordrawable.VectorDrawableFactory.get(VectorDrawableFactory.java:36)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:31)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:22)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:10)
at android.content.res.Resources.loadDrawable(Resources.java:2661)
at android.content.res.Resources.getDrawable(Resources.java:843)
at android.content.res.Resources.getDrawable(Resources.java:818)
at android.content.res.Resources.getDrawable(Resources.java:793)
android.view.InflateException: Binary XML file line #22: Error inflating class android.widget.ImageView
Binary XML file line #2 tag requires viewportHeight > 0
the 22 line contains this:
The App class contains this:
VectorDrawableCompat.enableResourceInterceptionFor(getResources(), R.drawable.mb_logo_vector);
What I do wrong?
P.S. In android 5 and higher it works fine,on android 4.0.4 it not works.
Hi @a-student .
Firstly, thanks for your cool library 👍
During its integration to my project I have experienced following issue:
:processDebugResources
Android/res/values/colors.xml
Error:(2) Attribute "strokeWidth" has already been defined
Error:(2) Attribute "strokeColor" has already been defined
Error:(2) Attribute "fillColor" has already been defined
Error:Execution failed for task ':processDebugResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/vadim/Library/Android/sdk/build-tools/23.0.0/aapt'' finished with non-zero exit value 1
Project settings:
compileSdkVersion 23
buildToolsVersion '23.0.0'
targetSdkVersion 23
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:23.0.1'
I hope you can shed light on this issues and what should I do.
Thanks in advance.
apply plugin: 'com.android.library'
repositories {
maven { url "http://dl.bintray.com/jjhesk/maven" }
maven { url 'http://dl.bintray.com/madcyph3r/maven/' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 17
targetSdkVersion 22
versionCode 10
versionName "1.5"
// generatedDensities = []
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
dependencies {
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.android.support:support-v13:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:percent:23.1.1'
compile 'net.soulwolf.widget:ratiolayout:1.0.0'
compile 'xyz.danoz:recyclerviewfastscroller:0.1.3'
compile 'com.ogaclejapan.smarttablayout:utils-v13:1.4.2@aar'
compile 'com.ogaclejapan.smarttablayout:library:1.4.2@aar'
compile 'com.marshalchen.ultimaterecyclerview:library:0.3.18'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.hkm.advancedtoolbar:advancedtoolbar:0.6.1'
// compile 'com.bettervectordrawable:lib:0.7'
// compile 'com.telly:mrvector:0.2.0'
// compile 'com.jakewharton:butterknife:7.0.1'
}
Hi there)
How can i connect animation to SVG in your library? Is it possible? Can I use standart way from here? Because that doesn't work(
http://developer.android.com/intl/ru/training/material/animations.html#AnimVector
I done this way.
Sory for my english) Thanks)
Hello, I found your librarry very interesting, but I have an issue with displaying of my vector images. Some of them displays incorrectly (some parts of pictures dissapear), and I'm not really sure why. I used your online converter. And the main thing that confuses me is sometimes they looks normal (not all of them, but still).
So I will be really pleased, if you help me resolve this problem )
And there is a link to an archive with my project, where drawables was made by your converter
http://rghost.ru/6l46wj7h7
Hi!
I'm trying to load very simple vector images that was created by standalone SvgToVectorDrawableConverter and get the error:
{path_to_project}\build\intermediates\res\merged{flavor}\debug\values\values.xml
Error:(302) Attribute "strokeWidth" has already been defined
Error:(302) Attribute "strokeColor" has already been defined
Error:(302) Attribute "fillColor" has already been defined
I've tried several images including airplane_vector.xml from demo project, but with the same result. Android Studio shows vector images in Design window without any problem.
Android Studio 1.5.1
com.android.tools.build:gradle 1.5.0
gradle 2.9
buildToolsVersion 23.0.2
com.bettervectordrawable:lib 0.7
Thanks for reply!
Drawable d = VectorDrawableCompat.inflate(true, res, ICON_RES_ID);
log:
VectorDrawableCompat: Inflating resource with id #0x7f020081 (system handling: false)
step 1: static VectorDrawable create(...
try {
final XmlPullParser parser = resources.getXml(rid);
log:
android.content.res.Resources$NotFoundException: File res/drawable-xhdpi-v4/ic_location_on.png from xml type xml resource ID #0x7f020081
png????
Is it possible to use this library to get the drawable to be animated like:
https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html
Lib does not catch xml file when android project is build with gradle version 1.5.0 or 2.0.0.-alpha1 in android 4.1.1
Fatal Exception: android.content.res.Resources$NotFoundException: File res/drawable-mdpi-v4/search.png from xml type xml resource ID #0x7f0200a1
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2145)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2100)
at android.content.res.Resources.getXml(Resources.java:901)
at com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.create(VectorDrawable.java:389)
at com.bettervectordrawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:95)
at com.bettervectordrawable.VectorDrawableFactory.get(VectorDrawableFactory.java:36)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:31)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:22)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:10)
at android.content.res.Resources.loadDrawable(Resources.java:1881)
at android.content.res.Resources.getDrawable(Resources.java:659)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.TintManager.getDrawable(TintManager.java:147)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
at android.support.v7.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:114)
at android.support.v7.widget.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:206)
at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:182)
at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:192)
at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:451)
at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138)
at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229)
at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284)
at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030)
at android.support.v7.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:1053)
at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:449)
at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:60)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.io.FileNotFoundException: Corrupt XML binary file
at android.content.res.AssetManager.openXmlAssetNative(AssetManager.java)
at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:487)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2127)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2100)
at android.content.res.Resources.getXml(Resources.java:901)
at com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.create(VectorDrawable.java:389)
at com.bettervectordrawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:95)
at com.bettervectordrawable.VectorDrawableFactory.get(VectorDrawableFactory.java:36)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:31)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:22)
at com.bettervectordrawable.LongSparseArrayDrawableConstantStateWrapper.get(LongSparseArrayDrawableConstantStateWrapper.java:10)
at android.content.res.Resources.loadDrawable(Resources.java:1881)
at android.content.res.Resources.getDrawable(Resources.java:659)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.TintManager.getDrawable(TintManager.java:147)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
at android.support.v7.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:114)
at android.support.v7.widget.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:206)
at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:182)
at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:192)
at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:451)
at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138)
at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229)
at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284)
at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030)
at android.support.v7.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:1053)
at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:449)
at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:60)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(NativeStart.java)
I get an crash when I use the BetterVectorDrawable in Notifications
NotificationCompat.Builder nb = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_statusbar_vector) .setAutoCancel(true) .setWhen(System.currentTimeMillis()) .setContentTitle(context.getString(R.string.app_name)) .setDefaults(Notification.DEFAULT_LIGHTS) ; ............................. Notification notification = nb.build(); manager.notify(lastId, notification);
StackTrace
Report: APP_VERSION_CODE= APP_VERSION_NAME= PHONE_MODEL=GT-I9505 ANDROID_VERSION=4.4.2 CUSTOM_DATA= STACK_TRACE=android.app.RemoteServiceException: Bad notification posted from package com.my.appname: Couldn't create icon: StatusBarIcon(pkg=com.my.appnameuser=0 id=0x7f0204a4 level=0 visible=true num=0 ) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1441) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5356) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at dalvik.system.NativeStart.main(Native Method)
from your README.md
There is an overload of the first method with a boolean parameter, which allows to force system handling of vector drawables on Android 5.0+
so this my code
VectorDrawableCompat.enableResourceInterceptionFor(true,getResources(),R.drawable.airplane_vector,R.drawable.bicycle_vector);
Class<?> cls = null;
try {
cls = Class.forName("android.content.res.Resources");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String name = "sPreloadedDrawables";
Field field = null;
try {
field = cls.getDeclaredField(name);
field.setAccessible(true);
@SuppressWarnings("unchecked")
LongSparseArray<Drawable.ConstantState>[] objField = (LongSparseArray<Drawable.ConstantState>[]) field.get(resources);
System.out.println(objField[0].size());
System.out.println("------------------------");
System.out.println(objField[1].size());
sPreloadedDrawables size never change What Is Wrong?? thk
Hi,
I've created xamarin binding for BetterVectorDrawable library. Can you please add link to this https://github.com/VysotskiVadim/XamarinBetterVectorDrawable repository in README.md in order to xamarin developers can find xamarin version of BetterVectorDrawable library.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.