wnafee / vector-compat Goto Github PK
View Code? Open in Web Editor NEWA support library for VectorDrawable and AnimatedVectorDrawable classes introduced in Lollipop
A support library for VectorDrawable and AnimatedVectorDrawable classes introduced in Lollipop
steps to repro - update demo/build.gradle
and change the buildToolsVersion
to 21.1.2
. compile and run. observe a crash on launch.
E/VectorDrawable( 1528): parser error
E/VectorDrawable( 1528): org.xmlpull.v1.XmlPullParserException: Binary XML file line #2<menu_vector> tag requires width > 0
E/VectorDrawable( 1528): at com.wnafee.vector.compat.VectorDrawable.updateStateFromTypedArray(VectorDrawable.java:400)
E/VectorDrawable( 1528): at com.wnafee.vector.compat.VectorDrawable.inflate(VectorDrawable.java:330)
E/VectorDrawable( 1528): at com.wnafee.vector.compat.VectorDrawable.create(VectorDrawable.java:304)
E/VectorDrawable( 1528): at com.wnafee.vector.compat.AnimatedVectorDrawable.inflate(AnimatedVectorDrawable.java:229)
E/VectorDrawable( 1528): at com.wnafee.vector.compat.AnimatedVectorDrawable.create(AnimatedVectorDrawable.java:204)
E/VectorDrawable( 1528): at com.wnafee.vector.compat.AnimatedVectorDrawable.getDrawable(AnimatedVectorDrawable.java:185)
E/VectorDrawable( 1528): at com.wnafee.vector.compat.ResourcesCompat.getDrawable(ResourcesCompat.java:44)
E/VectorDrawable( 1528): at com.wnafee.vector.MorphButton.<init>(MorphButton.java:79)
E/VectorDrawable( 1528): at com.wnafee.vector.MorphButton.<init>(MorphButton.java:58)
E/VectorDrawable( 1528): at java.lang.reflect.Constructor.constructNative(Native Method)
E/VectorDrawable( 1528): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
E/VectorDrawable( 1528): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
E/VectorDrawable( 1528): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
E/VectorDrawable( 1528): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
E/VectorDrawable( 1528): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
E/VectorDrawable( 1528): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
E/VectorDrawable( 1528): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
E/VectorDrawable( 1528): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:240)
E/VectorDrawable( 1528): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
E/VectorDrawable( 1528): at com.wnafee.vector.compat.demo.MainActivity.onCreate(MainActivity.java:27)
E/VectorDrawable( 1528): at android.app.Activity.performCreate(Activity.java:5231)
E/VectorDrawable( 1528): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/VectorDrawable( 1528): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
E/VectorDrawable( 1528): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
E/VectorDrawable( 1528): at android.app.ActivityThread.access$800(ActivityThread.java:135)
E/VectorDrawable( 1528): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/VectorDrawable( 1528): at android.os.Handler.dispatchMessage(Handler.java:102)
E/VectorDrawable( 1528): at android.os.Looper.loop(Looper.java:136)
E/VectorDrawable( 1528): at android.app.ActivityThread.main(ActivityThread.java:5001)
E/VectorDrawable( 1528): at java.lang.reflect.Method.invokeNative(Native Method)
E/VectorDrawable( 1528): at java.lang.reflect.Method.invoke(Method.java:515)
E/VectorDrawable( 1528): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/VectorDrawable( 1528): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/VectorDrawable( 1528): at dalvik.system.NativeStart.main(Native Method)
D/AndroidRuntime( 1528): Shutting down VM
W/dalvikvm( 1528): threadid=1: thread exiting with uncaught exception (group=0xa4d82b20)
E/AndroidRuntime( 1528): FATAL EXCEPTION: main
E/AndroidRuntime( 1528): Process: com.wnafee.vector.compat.demo, PID: 1528
E/AndroidRuntime( 1528): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wnafee.vector.compat.demo/com.wnafee.vector.compat.demo.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class com.wnafee.vector.MorphButton
E/AndroidRuntime( 1528): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
E/AndroidRuntime( 1528): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
E/AndroidRuntime( 1528): at android.app.ActivityThread.access$800(ActivityThread.java:135)
E/AndroidRuntime( 1528): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/AndroidRuntime( 1528): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 1528): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 1528): at android.app.ActivityThread.main(ActivityThread.java:5001)
E/AndroidRuntime( 1528): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1528): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 1528): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/AndroidRuntime( 1528): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/AndroidRuntime( 1528): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1528): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class com.wnafee.vector.MorphButton
E/AndroidRuntime( 1528): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
E/AndroidRuntime( 1528): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
E/AndroidRuntime( 1528): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
E/AndroidRuntime( 1528): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
E/AndroidRuntime( 1528): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
E/AndroidRuntime( 1528): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
E/AndroidRuntime( 1528): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:240)
E/AndroidRuntime( 1528): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
E/AndroidRuntime( 1528): at com.wnafee.vector.compat.demo.MainActivity.onCreate(MainActivity.java:27)
E/AndroidRuntime( 1528): at android.app.Activity.performCreate(Activity.java:5231)
E/AndroidRuntime( 1528): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime( 1528): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
E/AndroidRuntime( 1528): ... 11 more
E/AndroidRuntime( 1528): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 1528): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 1528): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
E/AndroidRuntime( 1528): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
E/AndroidRuntime( 1528): ... 22 more
E/AndroidRuntime( 1528): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 1528): at com.wnafee.vector.compat.AnimatedVectorDrawable.inflate(AnimatedVectorDrawable.java:229)
E/AndroidRuntime( 1528): at com.wnafee.vector.compat.AnimatedVectorDrawable.create(AnimatedVectorDrawable.java:204)
E/AndroidRuntime( 1528): at com.wnafee.vector.compat.AnimatedVectorDrawable.getDrawable(AnimatedVectorDrawable.java:185)
E/AndroidRuntime( 1528): at com.wnafee.vector.compat.ResourcesCompat.getDrawable(ResourcesCompat.java:44)
E/AndroidRuntime( 1528): at com.wnafee.vector.MorphButton.<init>(MorphButton.java:79)
E/AndroidRuntime( 1528): at com.wnafee.vector.MorphButton.<init>(MorphButton.java:58)
E/AndroidRuntime( 1528): ... 25 more
W/ActivityManager( 511): Force finishing activity com.wnafee.vector.compat.demo/.MainActivity
upgrading to a newer build tools (22.0.1
, for example) fixes this problem. filing this ticket for two reasons:
Is it intentional ?
Drawable stateButtonDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ucrop_ic_cross,null).mutate();
got same error
Is it planned for this project? Or do you want to keep it as minSdk 14?
"#000000" in attribute "valueTo" cannot be converted to float.
for
<objectAnimator
android:duration="@integer/morphing_time"
android:propertyName="fillColor"
android:valueFrom="@color/marine_default"
android:valueTo="@color/black"/>
what is wrong here, anyone?
Hi.
I am using your lib and also ViewPagerIndicator (com.viewpagerindicator:library:2.4.1@aar).
Gradle gets me these errors:
Error:(1) Attribute "strokeWidth" has already been defined
Error:(1) Attribute "strokeWidth" has already been defined
Error:(1) Attribute "fillColor" has already been defined
I think it is something with naming convention (i found similiar problem here for some other lib, maybe it can help you: https://bitbucket.org/mobigosoft/graphlib/issue/1/error-attribute-strokecolor-has-already)
Google has released support for API 7 and above for VectorDrawable:
http://android-developers.blogspot.co.il/2016/02/android-support-library-232.html
Can you please show a sample of how to use it?
I'm trying to use the MorphButton
to transition from one drawable to another. Both vc_startDrawable
& vc_endDrawable
use an animated-vector
. The objectAnimator
animates the trimPathStart
property of a path vector. Everything's working fine on Android Lollipop but on kitkat or below, the app's crashing as soon as the activity with the MorphButton
starts up. Since I'm using MorphButton
, I'm not doing any inflation in java. I'm using buildToolsVersion '23.0.2'
& minSdkVersion 14
. Below is the necessary code:
<com.wnafee.vector.MorphButton
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
app:vc_endDrawable="@drawable/anim_end"
app:vc_startDrawable="@drawable/anim_start" />
drawables anim_end and anim_start are similar to each other:
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/sample">
<target
android:name="b"
android:animation="@anim/anim_empty" />
<target
android:name="s"
android:animation="@anim/anim_fill" />
</animated-vector>
animators anim_fill and anim_empty are similar to each other:
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:propertyName="trimPathStart"
android:valueFrom="1"
android:valueTo="0"
android:duration="@integer/anim_duration"
android:interpolator="@android:interpolator/linear_out_slow_in"
android:valueType="floatType"
app:vc_valueType="floatType"/>
vector drawable sample is as follows:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:width="250dp"
android:height="24dp"
android:viewportWidth="250"
android:viewportHeight="24"
app:vc_viewportWidth="250"
app:vc_viewportHeight="24">
<path
android:name="s"
android:pathData="@string/s_path"
android:strokeWidth="1"
android:strokeColor="@color/c1"
android:strokeAlpha="0.8"
android:strokeLineCap="round"
app:vc_pathData="@string/s_path"
app:vc_strokeWidth="1"
app:vc_strokeColor="@color/c1"
app:vc_strokeAlpha="0.8"
app:vc_strokeLineCap="round" />
<path
android:name="b"
android:pathData="@string/b_path"
android:strokeWidth="1"
android:strokeColor="@color/c1"
android:strokeAlpha="0.8"
android:strokeLineCap="square"
app:vc_pathData="@string/b_path"
app:vc_strokeWidth="1"
app:vc_strokeColor="@color/c1"
app:vc_strokeAlpha="0.8"
app:vc_strokeLineCap="square" />
</vector>
And finally here's the log report when the crash occurs:
-12 15:53:02.118 27342-27342/com.example E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example, PID: 27342
android.view.InflateException: Binary XML file line #56: Error inflating class com.wnafee.vector.MorphButton
at android.view.LayoutInflater.createView(LayoutInflater.java:627)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:703)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:771)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.example.MyFragment.onCreateView(MyFragment.java:65)
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.FragmentManagerImpl$1.run(FragmentManager.java:443)
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:5433)
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:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:601)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:703)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:771)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.example.MyFragment.onCreateView(MyFragment.java:65)
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.FragmentManagerImpl$1.run(FragmentManager.java:443)
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:5433)
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:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/anim_start.xml from drawable resource ID #0x7f02003c
at android.content.res.Resources.loadDrawable(Resources.java:3451)
at android.content.res.Resources.getDrawable(Resources.java:1894)
at com.wnafee.vector.compat.ResourcesCompat.getDrawable(ResourcesCompat.java:34)
at com.wnafee.vector.MorphButton.setStartDrawable(MorphButton.java:282)
at com.wnafee.vector.MorphButton.<init>(MorphButton.java:141)
at com.wnafee.vector.MorphButton.<init>(MorphButton.java:113)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:601)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:703)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:771)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.example.MyFragment.onCreateView(MyFragment.java:65)
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.FragmentManagerImpl$1.run(FragmentManager.java:443)
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:5433)
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:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag animated-vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:969)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:913)
at android.content.res.Resources.loadDrawable(Resources.java:3447)
at android.content.res.Resources.getDrawable(Resources.java:1894)
at com.wnafee.vector.compat.ResourcesCompat.getDrawable(ResourcesCompat.java:34)
at com.wnafee.vector.MorphButton.setStartDrawable(MorphButton.java:282)
at com.wnafee.vector.MorphButton.<init>(MorphButton.java:141)
at com.wnafee.vector.MorphButton.<init>(MorphButton.java:113)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:601)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:703)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:771)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.example.MyFragment.onCreateView(MyFragment.java:65)
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.FragmentManagerImpl$1.run(FragmentManager.java:443)
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:5433)
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:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Line 65 of MyFragment is:
View rootView = inflater.inflate(R.layout.fragment_layout, container, false);
I believe the problem is somewhere in the ResourcesCompat
. It's somehow not using the library's own AnimatedVectorDrawable
for inflation.
If any other info is needed, please let me know. Please guide me where I'm going wrong or suggest a workaround. I'm stuck here and very close to my deadline. Thanks.
Sometimes when I click the buttons (specifically the pause to play button) it lags :/
Source code is here: github.com/DominionOS/packages_apps_Music
Go ahead and laugh at that mess of code
I receive this error on Nexus 7 2013 with my project using vector-compat:
Failed to load animators. Either the AnimatedVectorDrawable must be created using a Resources object or applyTheme() must be called with a non-null Theme object.
The button is not functional, can't be clicked.
Is there a way how to fix this ? Working good on L devices and Kitkat.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.wnafee.vector.compat.demo, PID: 2360
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wnafee.vector.compat.demo/com.wnafee.vector.compat.demo.MainActivity}: android.view.InflateException: Binary XML file line #0: Error inflating class com.wnafee.vector.MorphButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class com.wnafee.vector.MorphButton
at android.view.LayoutInflater.createView(LayoutInflater.java:621)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.wnafee.vector.compat.demo.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:595)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.wnafee.vector.compat.demo.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-xxhdpi-v4/ic_arrow_vector.png from xml type xml resource ID #0x7f060054
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2361)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2316)
at android.content.res.Resources.getXml(Resources.java:988)
at com.wnafee.vector.compat.VectorDrawable.create(VectorDrawable.java:290)
at com.wnafee.vector.compat.AnimatedVectorDrawable.inflate(AnimatedVectorDrawable.java:229)
at com.wnafee.vector.compat.AnimatedVectorDrawable.create(AnimatedVectorDrawable.java:204)
at com.wnafee.vector.compat.AnimatedVectorDrawable.getDrawable(AnimatedVectorDrawable.java:185)
at com.wnafee.vector.compat.ResourcesCompat.getDrawable(ResourcesCompat.java:44)
at com.wnafee.vector.MorphButton.setStartDrawable(MorphButton.java:282)
at com.wnafee.vector.MorphButton.(MorphButton.java:141)
at com.wnafee.vector.MorphButton.(MorphButton.java:113)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:595)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.wnafee.vector.compat.demo.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.FileNotFoundException: Corrupt XML binary file
at android.content.res.AssetManager.openXmlAssetNative(Native Method)
at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:488)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2343)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2316)
at android.content.res.Resources.getXml(Resources.java:988)
at com.wnafee.vector.compat.VectorDrawable.create(VectorDrawable.java:290)
at com.wnafee.vector.compat.AnimatedVectorDrawable.inflate(AnimatedVectorDrawable.java:229)
at com.wnafee.vector.compat.AnimatedVectorDrawable.create(AnimatedVectorDrawable.java:204)
at com.wnafee.vector.compat.AnimatedVectorDrawable.getDrawable(AnimatedVectorDrawable.java:185)
at com.wnafee.vector.compat.ResourcesCompat.getDrawable(ResourcesCompat.java:44)
at com.wnafee.vector.MorphButton.setStartDrawable(MorphButton.java:282)
at com.wnafee.vector.MorphButton.(MorphButton.java:141)
at com.wnafee.vector.MorphButton.(MorphButton.java:113)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:595)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.wnafee.vector.compat.demo.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
I would like to request an animation of a plus to a tick for use in RecyclerView items, some kind of spinning morphing thing would be cool!
Thanks!
I believe these were used for the demo purposes but these are currently part of the maven aar and I am getting errors for these vectors. these vectors should not be the part of maven library.
D:\workspace\CoCoin\app\build\intermediates\exploded-aar\com.wnafee\vector-compat\1.0.5\res\drawable\ic_arrow_vector.xml
:app:mergeDebugResources FAILED
Error:Execution failed for task ':app:mergeDebugResources'.
D:\workspace\CoCoin\app\build\intermediates\exploded-aar\com.wnafee\vector-compat\1.0.5\res\drawable\ic_arrow_vector.xml: Error: error in parsing "g/"
What can I do to make my project correct? Thanks.
Hi,
I've attempted to implement your library and it works great on Android 5.X.X and above however Im getting some issues on devices running 4.X.X. Below is a partial of my xml for the vector drawable as the path data is quite long. Ive also got both app:vc_pathData
and app:vc_fillColor
on every path tag as well as the normal android:
ones
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:width="85dp"
android:height="36dp"
android:viewportWidth="85"
android:viewportHeight="36"
app:vc_viewportWidth="85"
app:vc_viewportHeight="36">
Im applying this to the MorphButton in xml in my layout however I get the error in the title when I run on devices 4.X.X.
What am I missing?
Failed when try animate property trimPathEnd or try animate clip-path with pathData property.
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/iid/InstanceID; at com.b.h.run(AppsFlyerLib.java:232) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.iid.InstanceID" on path: DexPathList[[zip file "/data/app/com.tarasovmobile.gtd-2/base.apk"],nativeLibraryDirectories=[/data/app/com.tarasovmobile.gtd-2/lib/arm, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at com.b.h.run(AppsFlyerLib.java:232) at java.lang.Thread.run(Thread.java:818) Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.iid.InstanceID at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 3 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Would it be possible to have round buttons instead of square ones?
I tried:
mButton.setStartDrawable(VectorDrawable.getDrawable(this, R.drawable.ic_play));
mButton.setEndDrawable(VectorDrawable.getDrawable(this, R.drawable.ic_pause));
Error is:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Rect android.graphics.drawable.Drawable.getBounds()' on a null object reference
I tried:
mButton.setStartDrawable(AnimatedVectorDrawable.getDrawable(this, R.drawable.ic_play_animatable));
mButton.setEndDrawable(AnimatedVectorDrawable.getDrawable(this, R.drawable.ic_pause_animatable));
Error is:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Rect android.graphics.drawable.Drawable.getBounds()' on a null object reference
Quick question for ya, I'm still learning where to find everything but I cannot seem to locate where to change the color of the actual button, I can change the background and the foreground color but not the button. If you can point me to it, that would be fantastic!
Is there some trick to getting a project to use vector-compat, beyond adding it to the gradle dependency list? When I try to display a vector drawable (not animated, not MorphButton), it crashes when run under KitKat (API 19).
The error is:
org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag vector
The stack trace shows no sign of com.wnafee, so I can't tell if it is actually functioning.
For reference, here is the drawable I'm trying to display (as a Button background):
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:width="24dp"
android:height="24dp"
app:vc_viewportHeight="24"
app:vc_viewportWidth="24"
android:viewportHeight="24"
android:viewportWidth="24">
<path
app:vc_fillColor="#FFFFFF"
app:vc_pathData="@string/vector_qrcode"
android:fillColor="#FFFFFF"
android:pathData="@string/vector_qrcode"/>
</vector>
In my drawable
folder I have a ic_menu_refresh.xml
file, which defines a refresh symbol vector:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:pathData="M17.6,6.4C16.2,4.9 14.2,4 12,4c-4.4,0 -8,3.6 -8,8s3.6,8 8,8c3.7,0 6.8,-2.6 7.7,-6l-2.1,0c-0.8,2.3 -3,4 -5.6,4c-3.3,0 -6,-2.7 -6,-6s2.7,-6 6,-6c1.7,0 3.1,0.7 4.2,1.8L13,11l7,0L20,4L17.6,6.4z"
android:fillColor="@color/white"/>
I get an error in Android Studio that says, <vector> requires API level 21
. I want the app to support versions of Android lower than API level 21. My minSdkVersion
is 16
, compileSdkVersion
and targetSdkVersion
are 22
.
And I have a Floating Button which uses this icon:
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@drawable/ic_menu_refresh"
app:elevation="6dp"
app:pressedTranslationZ="12dp" />
When I run my app it gives me an error:
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
Hey! I'm new to support libraries to please bear with me!
I'm confused about how one installs the library:
-Should I download the .pom or the .aar file?
-Where should I put the file?
Thanks for your help!
(I'm using Android Studio and the Android SDK.)
Is there any way with this library to load in the drawable at a scaled size? my drawables bounds are 512dp x 512dp but are also displayed at a smaller size (about 96dp x 96dp) and is causing memory crashes because its still rendering the drawable to a bitmap at a size of 512dp x 512dp.
Root cause is the method createCachedBitmapIfNeeded
Hello,
Nice insightful library.
I shall be very grateful if you could help me in this issue.
I have svg file and want to convert it in to Vector Drawable programmatically.
Please help in this.
Looking forward to hear from you.
Can vector-compat supports SVG rendering animation path? For example “trimPathStart”。I find vector-compat have "vc_trimPathStart" but I would not use it。
if vector-compat supports SVG rendering animation path,How should I use。
I write the Animator, can not be used
Hello! Congratulations at first.
I want this amazing animation on the button of my radio player, but im already using a FAB lib (https://github.com/Clans/FloatingActionButton) and I was not able to understand how to put this effect on my button.
Any help is appreciated. Thanks in advance.
I have checkbox and set buttonDrawable is "animation_selector". When run app, it is crashed with error "Binary XML file line #1: invalid drawable tag animated-selector".
How to use the library for this?
Maybe I've missed something, but I stumbled a little.
I have an xml layout with button, in Java code I'm using
Drawable avd = ResourcesCompat.getDrawable(getActivity(), R.drawable.btn_signin_avd);
mBtnSignin.setBackground(avd);
Animations working good, but when not animating my button is transparent, though on Lollipop devices it shows background descrided in the <vector><path>pathData</path></vector>
section. And I duplicate pathData
attribute value with app:vc_pathData
.
I'm trying to use the vector drawables on a button, specifically the drawableLeft and drawableRight attributes. This is done in code like this:
Drawable drawable = ResourcesCompat.getDrawable(context, R.drawable.vector_icon);
button.setCompoundDrawables(drawable, null, null, null);
However, if I put the same drawable inside an ImageView via setDrawable, then it works:
imageView.setImageDrawable(drawable);
This seems to be happening on 5.0, 4.4 and 4.3. And interestingly the drawable on the button would actually draw if I have an image view also visible in the view using the same drawable.
I want to manually handle animation changes in code so I tried to set app:vc_autoStartAnimation="false"
like this:
<com.wnafee.vector.MorphButton
android:id="@+id/play_pause"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:srcCompat="@drawable/ic_play"
app:vc_startDrawable="@drawable/ic_pause_to_play"
app:vc_endDrawable="@drawable/ic_play_to_pause"
app:vc_autoStartAnimation="false"
android:onClick="play_pause"/>
But even if I remove the onClick function it autostarts when touching it on the smartphone!
Is there any other possibility to do this?
This is in android studio 15:
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.foo.bar"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.wnafee:vector-compat:1.0.5'
}
offending file
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:width="48dp"
android:height="48dp"
android:viewportWidth="24"
android:viewportHeight="24"
app:vc_viewportWidth="24"
app:vc_viewportHeight="24" >
<group
android:name="rotationGroup"
android:pivotX="12.0"
android:pivotY="12.0"
android:rotation="0.0">
<path
android:name="v"
android:fillColor="#000000"
android:pathData="@string/path_drawer"
app:vc_fillColor="#000000"
app:vc_pathData="@string/path_drawer"/>
</group>
</vector>
<!-- From: file:/Users/wnafee/code/vector-compat/library/src/main/res/drawable/ic_drawer_vector.xml -->
error:
Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]
Configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2311Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72311Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:app:prepareComWnafeeVectorCompat105Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources
E:\AndroidProjects\androapplication\app\build\intermediates\exploded-aar\com.wnafee\vector-compat\1.0.5\res\drawable\ic_drawer_vector.xml: Error: error in parsing "g/"
:app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> E:\AndroidProjects\androapplication\app\build\intermediates\exploded-aar\com.wnafee\vector-compat\1.0.5\res\drawable\ic_drawer_vector.xml: Error: error in parsing "g/"
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 58.321 secs
Doesn't work with BuildTools 26.0.2
but with 26.0.0 work properly
SVG and VectorDrawable paths can both contain strings like 1.5.5
, because the parser interprets it as 1.5 0.5
. However, vector-compat crashes if the path includes such a string, and you see an error in Logcat like:
E/PathParser( 681): error in parsing "s 50.916.958150 0 50"
D/AndroidRuntime( 681): Shutting down VM
W/dalvikvm( 681): threadid=1: thread exiting with uncaught exception (group=0x41590ba8)
E/AndroidRuntime( 681): FATAL EXCEPTION: main
E/AndroidRuntime( 681): Process: com.wnafee.vector.compat.demo, PID: 681
E/AndroidRuntime( 681): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wnafee.vector.compat.demo/com.wnafee.vector.compat.demo.MainActivity}: android.cont
ent.res.Resources$NotFoundException: File res/drawable/basic_bezier.xml from drawable resource ID #0x7f02003b
E/AndroidRuntime( 681): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
E/AndroidRuntime( 681): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
E/AndroidRuntime( 681): at android.app.ActivityThread.access$800(ActivityThread.java:135)
E/AndroidRuntime( 681): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/AndroidRuntime( 681): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 681): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 681): at android.app.ActivityThread.main(ActivityThread.java:5001)
E/AndroidRuntime( 681): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 681): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 681): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/AndroidRuntime( 681): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/AndroidRuntime( 681): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 681): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/basic_bezier.xml from drawable resource ID #0x7f02003b
E/AndroidRuntime( 681): at android.content.res.Resources.loadDrawable(Resources.java:2096)
E/AndroidRuntime( 681): at android.content.res.Resources.getDrawable(Resources.java:700)
E/AndroidRuntime( 681): at com.wnafee.vector.compat.ResourcesCompat.getDrawable(ResourcesCompat.java:34)
E/AndroidRuntime( 681): at com.wnafee.vector.compat.demo.MainActivity.onCreate(MainActivity.java:63)
E/AndroidRuntime( 681): at android.app.Activity.performCreate(Activity.java:5231)
E/AndroidRuntime( 681): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime( 681): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
E/AndroidRuntime( 681): ... 11 more
E/AndroidRuntime( 681): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag vector
E/AndroidRuntime( 681): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
E/AndroidRuntime( 681): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
E/AndroidRuntime( 681): at android.content.res.Resources.loadDrawable(Resources.java:2092)
E/AndroidRuntime( 681): ... 17 more
The current 1.4.0-beta1 release of the android gradle plugin has new features that regard vector drawables (from http://tools.android.com/tech-docs/new-build-system):
PNGs are generated for every vector drawable found in a resource directory that does not specify an API version (or specifies a version lower than 21).
This only happens if minSdk is below 21.
Densities to use can be set using the new "generatedDensities" property in defaultConfig or per-flavor.
When I use vector-compat in a project together with 1.4.0-beta1, the mergeDebugResources
tasks fails while trying to process the vector drawables:
Generating PNG: [/android-app/app/build/generated/res/pngs/debug/drawable-xxxhdpi/ic_pause_vector.png] from [/android-app/app/build/intermediates/exploded-aar/com.wnafee/vector-compat/1.0.5/res/drawable/ic_pause_vector.xml]
Stacktrace:
Caused by: java.lang.NullPointerException
at com.android.ide.common.vectordrawable.VdParser.parse(VdParser.java:181)
at com.android.ide.common.vectordrawable.VdPreview.getPreviewFromVectorXml(VdPreview.java:249)
at com.android.builder.png.VectorDrawableRenderer.generateFile(VectorDrawableRenderer.java:133)
at com.android.ide.common.res2.MergedResourceWriter$1.call(MergedResourceWriter.java:191)
at com.android.ide.common.res2.MergedResourceWriter$1.call(MergedResourceWriter.java:174)
I can't tell what part in the vector drawable xml causes this.
From what I understand, it shouldn't be necessary to generate the PNGs from these vector drawables since this library contains all the code for backwards compatibility to display them directly. So when placing them in drawable-v21
the gradle plugin would ignore them perhaps?
Now I know 1.4.0 is just a beta release so far and things might change, I just couldn't find a workaround so far to make it work in my project together with vector-compat.
First and foremost, thanks for all your hard work on this library!
On Android API 14 devices, animating a vector group works beautifully but when attempting to animate vector path attributes (e.g. fillAlpha
on path circlePath
of circle.xml
below) an exception is thrown:
07-15 23:51:44.013 17042-17042/com.example.vector_compat_test E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vector_compat_test/com.example.vector_compat_test.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/circle_fade.xml from drawable resource ID #0x7f02003c
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
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(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/circle_fade.xml from drawable resource ID #0x7f02003c
at android.content.res.Resources.loadDrawable(Resources.java:1918)
at android.content.res.Resources.getDrawable(Resources.java:659)
at com.wnafee.vector.compat.ResourcesCompat.getDrawable(ResourcesCompat.java:34)
at com.example.vector_compat_test.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
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(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag animated-vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:877)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
at android.content.res.Resources.loadDrawable(Resources.java:1915)
at android.content.res.Resources.getDrawable(Resources.java:659)
at com.wnafee.vector.compat.ResourcesCompat.getDrawable(ResourcesCompat.java:34)
at com.example.vector_compat_test.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
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(Native Method)
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:width="150dp"
android:height="150dp"
android:viewportWidth="100"
android:viewportHeight="100"
app:vc_viewportWidth="100"
app:vc_viewportHeight="100">
<group
android:name="circleGroup"
android:rotation="0"
android:pivotX="50"
android:pivotY="50">
<!--
Circle path data generated with:
CX: 50.5, CY: 50.5, R: 28
http://complexdan.com/svg-circleellipse-to-path-converter/
-->
<path
android:name="circlePath"
android:fillColor="@android:color/white"
android:fillAlpha="1.0"
android:pathData="@string/path_circle"
app:vc_fillColor="@android:color/white"
app:vc_fillAlpha="1.0"
app:vc_pathData="@string/path_circle"/>
</group>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/circle">
<target
android:name="circlePath"
android:animation="@animator/fade"/>
</animated-vector>
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="fillAlpha"
android:duration="@android:integer/config_longAnimTime"
android:valueFrom="1.0"
android:valueTo="0.0"
android:repeatCount="1"
android:repeatMode="reverse"/>
...
import com.wnafee.vector.compat.ResourcesCompat;
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Drawable drawable = ResourcesCompat.getDrawable(this, R.drawable.circle_fade);
ImageView circleView = (ImageView) findViewById(R.id.circle);
circleView.setImageDrawable(drawable);
circleView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (drawable instanceof Animatable) {
((Animatable) drawable).start();
} else {
Log.d(TAG, "!(drawable instanceof Animatable)");
}
}
});
}
}
The same project works when running on Android API 21+ devices.
verision: 1.0.5
layout:
<com.wnafee.vector.MorphButton
android:layout_marginRight="8dp"
android:layout_marginTop="16dp"
android:layout_width="24dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="16dp"
android:layout_height="24dp"
app:vc_startDrawable="@drawable/ic_history_black_24px" />
on click throws:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Rect android.graphics.drawable.Drawable.getBounds()' on a null object reference
at com.wnafee.vector.MorphButton.setCurrentDrawable(MorphButton.java:336)
at com.wnafee.vector.MorphButton.setState(MorphButton.java:381)
at com.wnafee.vector.MorphButton.toggle(MorphButton.java:173)
at android.widget.CompoundButton.performClick(CompoundButton.java:127)
at android.view.View$PerformClick.run(View.java:20926)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
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:1389)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
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.