About dynamic generation and loading of VectorDrawables

25 Views Asked by At

I'm in the development of an android app that needs to show VectorDrawables in a dynamic fashion, so I wrote a C library that outputs these for me based on an input string.

I also integrated the usual hello world NDK sample from within my project, that gradle compiles as a shared library and includes in the bundle so that I can access it from java at runtime, meaning to be replaced by my library's code next.

During the next phase of my research to fully integrate it from within my app, I found out working with VectorDrawables in a dynamic fashion is not something as trivial as I originally thought.

What options do I have in 2023? I've seen vector-compat and VectorMaster projects, accessing the inners of AnimatedVectorDrawables through reflection (I don't need animations, plus that I'd prefer avoiding reflections if possible), some other answers here regarding trying to load these as streams at runtime, and little else.

My library currently outputs VectorDrawables as regular XML files (that I have thoroughly tested to be valid), but I could investigate on how to compile these to binary to feed my application if needed. After all this is all a personal project and I do not intend to support any older androids or devices other than mine.

The need for dynamic VectorDrawables is actually a requirement for me, though, as there are so many combinations that storing these as individual resources is not an option.

Has anybody out there done this and can offer some advice, share some tips, or even show some example code?

What I've tried block: I have written and refined the library to the point where these VectorDrawables fully comply with the requirements, which include being valid for me on every possible case, and giving output XML files my app can can (statically) load and show at runtime.

0

There are 0 best solutions below