2

I have an SVG file with 27162 lines, some with a huge number of columns. So when I run it, this exception is shown:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.iamrichifeelamerican/global.controllers.ActivityHandlingFragments}: android.view.InflateException: Binary XML file line #370: Binary XML file line #370: Error inflating class ImageView

[...] Caused by: java.lang.IllegalArgumentException: Invalid pathData. Failure occurred at position 2 of path: STRING_TOO_LARGE

Is there any way to exceed this limit?

Imagine a project in which you have to use a huge SVG (and an SVG'd be actually required): how the firm would deal with this problem?

JarsOfJam-Scheduler
  • 2,809
  • 3
  • 31
  • 70
  • How are you using this SVG? Android doesn't support SVG directly. Are you importing it into a vector drawable resource? Are you using some SVG library? – CommonsWare Apr 11 '19 at 21:58
  • I just use the Asset Vector wizard of Android Studio, and set the XML drawable containing the svg XML elements as the source of an image view – JarsOfJam-Scheduler Apr 11 '19 at 22:02
  • If you can give Google a project that reproduces the problem, you might file an issue. Either Android Studio should prevent you from creating it, or Android should accept it. In terms of then actually showing this SVG, there are [some libraries](https://android-arsenal.com/tag/96) you could look at, where your SVG would be just an asset or raw resource, and the library code would interpret it at runtime. Or, use a `WebView`. – CommonsWare Apr 11 '19 at 22:05

2 Answers2

3

"Invalid pathData" means that your SVG contains a <path> element that has a path description (d attribute) that the VectorDrawable conversion code didn't understand.

To work around this, you will have to find the problematic path element and tweak it so that it converts properly.

Unfortunately AndroidStudio is not very informative when it fails like this. So you will have to find the problematic <path> by trial and error. Ie. narrow down the search by removing some of the <path> elements until you find it.

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
  • 1
    Why was this answer voted down? I had this issue and it was solved by finding a path in the SVG file that had a huge number of bezier curves and simplifying them (using Inkscape's Extension->Modify Path->Flatten Beziers). This reduced the length of the path, the string wasn't truncated and then the SVG loaded fine. – Steve Moseley Mar 17 '20 at 23:45
-1

I know this is an old topic. But in cases for further readers that had the same problem, I just applied the following solution : Simplying vector drawable for android and it worked like a charm

Damiii
  • 1,363
  • 4
  • 25
  • 46