Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java – How to handle large amount of animated vector drawables?

Posted on November 11, 2022 By

Solution 1 :

I’ve managed to solve the long compilation time problem and just in case anyone might stumble upon this post, I’ll post my solution here.

Apparently, 9000+ AnimatedVectorDrawable wasn’t the problem. The problem was that I was using Inline complex XML resources method to create my AnimatedVectorDrawable. Inside each of my AnimatedVectorDrawable contains multiple VectorDrawables and ObjectAnimators. This means that even if there is only 1 AnimatedVectorDrawable XML file, the AAPT tool will create multiple XMLs for the VectorDrawables and ObjectAnimators which also means that I ended up with way more than 9000+ AnimatedVectorDrawables. This was the cause of the long compilation time.

So, I ended up creating VectorDrawables instead and created a Class to handle the ObjectAnimators at runtime. However, to achieve this, I had to use Java reflection techniques to access the private getTargetByName function in VectorDrawable to get the Target object for the ObjectAnimators and use the invalidateSelf function of the VectorDrawable in a Thread to update the VectorDrawable at runtime.

Problem :

I am making a Chinese dictionary app that can show users the Chinese characters stroke order animation. I am using MakeMeAHanzi as the source which can be used to generate animated SVGs for the stroke order animation. One SVG for one Chinese character. Using the same concept, I generated animated vector drawables instead.

Currently my android app contains 9000+ animated vector drawables and it is taking a long time to build. I am also getting this error that only occurs when I add in the 9000+ animated vector drawables:

Waited 10 minutes (plus 203200 nanoseconds delay) for com.googl[email protected][status=PENDING]

I’ve considered using GIFs and load it from the expansion file instead but I would really like to have the advantage of resolution-independence. I’ve tried loading the animated vector drawables from the expansion file but it seems that I can’t load .xml from the file system as drawables unless I precompile it as binary XML and I think this will be my last resort as I am still not sure how to achieve this yet since I am unable to build the APK (I can extract precompiled binary XML from the APK).

READ  [FIXED] android - How to solve unresolved reference fragment?
Powered by Inline Related Posts

May I know if there are more efficient ways of handling large amount of vector drawables or other alternatives to handling this situation? Thank you.

Comments

Comment posted by asky

Can I ask why you have so many animated vector drawables? the fact that you have over 9000 of them is a bit of a code smell.

Comment posted by CommonsWare

You could try creating a library module in your project, putting these resources in the library module, and having your app module depend on the library module. The initial build will take the time that your are used to, but it may help with future builds. Basically, you want the build system to not have to mess with these resources very often. But, beyond that, I’ll echo asky’s question: why do you have 9000+ animated vector drawables in the first place? We cannot advise you on “other alternatives to handling this situation” until you explain in detail what you are doing with them.

Comment posted by MakeMeAHanzi

I’m actually making a Chinese dictionary that shows the stroke order animations. The source that I used is from

Comment posted by Edwin

@asky I do agree that my approach is problematic. I am still looking for a proper way to handle it.

Comment posted by asky

The use case you described seems like a good reason to have 9000 SVGs. There’s probably no way to reduce that number and have the app serve its intended purpose. I have never run into this problem before, so all I can think of is that if you expect the user to only look at a few drawables simultaneously, you could generate drawables from SVGs at runtime. I don’t know of a good choice of library to do this (many android svg libraries appear to be unmaintained), so this option might not work in the end.

READ  [FIXED] android - Calling native function from TypeScript in react-native
Powered by Inline Related Posts

Android Tags:android, android-resources, android-studio, animatedvectordrawable, java

Post navigation

Previous Post: [FIXED] Android Studios error : Unable to locate adb location
Next Post: [FIXED] android – Here Maps Navigation samples seem to be missing the Navigation Library

Related Posts

[FIXED] android – Bi-directional communication between Google Assistant and my App Android
[FIXED] android studio – Best way to store data for multiple category? Android
[FIXED] sql – Return specific Row first and then other Row follow Android
[FIXED] flutter – Android licenses is toggling between not found and not accepted Android
[FIXED] I am new in coding Android studio. I was trying to implement PlacePicker Android
[FIXED] android – how to show timepicker fragment inside another fragment Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme