XmlPullParserException Binary XML file line #17<vector> tag requires viewportWidth > 0
Asked Answered
A

8

21

This is a follow up question to this question:

Update Android Support Library to 23.2.0 cause error: XmlPullParserException Binary XML file line #17<vector> tag requires viewportWidth > 0

I also updated the support library to 23.2 and started getting the error:

XmlPullParserException Binary XML file line #17<vector> tag requires viewportWidth > 0

That question solved it for Android Studio and Gradle. How can this be solved when using Eclipse without Gradle?

Apices answered 26/2, 2016 at 23:11 Comment(1)
A
5

A previous answer to this question had a solution for developers who use Gradle, but I don't use Gradle so I want to summarize his answer which helped several people and what I eventually did. I accepted my own answer and not his since like I said, I don't use Gradle so I did not use what he wrote.

I did several things for it to work in the end. Possible solutions are:

First for Gradle users:

1) Revert the support library to an older version, since this one has a bug.

2) use compile 'com.android.support:appcompat-v7:23.2.1' as the bug was fixed there.

3) for Gradle Plugin 2.0:

android {  
    defaultConfig {  
        vectorDrawables.useSupportLibrary = true  
    }  
}

Or you can use Grade Build Tools 1.5.0 (classpath 'com.android.tools.build:gradle:1.5.0')

defaultConfig {
    generatedDensities = []
}

// no need for this with Gradle 2.0

aaptOptions {
    additionalParameters "--no-version-vectors"
}

This is the part for non Gradle users:

1) Open SDK manager.

2) Uninstalled both "Android Wear X" (where X is ARM or Intel) from APIs 22 and 23.

3) I then still had a compilation error in one of the styles of the AppCompat library. I simply commented them out (I'll risk the very specific device not working if it uses that very specific style).

After that I cleaned the project and it just started to work.

Apices answered 21/4, 2016 at 17:29 Comment(0)
S
9

You can either switch back to the previous version of the appcompat library (Quick fix):

compile 'com.android.support:appcompat-v7:23.1.1'

Or keep the current library version and make the appropriate update to your build gradle file as explained by google in version 23.2.0 release note.

//for Gradle Plugin 2.0+  
android {  
    defaultConfig {  
        vectorDrawables.useSupportLibrary = true  
    }  
}

If you are using Gradle 1.5 you’ll instead use

defaultConfig {
    generatedDensities = []
}

// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
    additionalParameters "--no-version-vectors"
}

Don't forget to update your gradle build tool to version 1.5.0 at least or you couldn't use the new parameters like generatedDensities:

classpath 'com.android.tools.build:gradle:1.5.0'

More infos on why here

Setting answered 2/3, 2016 at 14:21 Comment(1)
this works for me.my gradle build tool version is 1.3.1. i just add aaptOptions { additionalParameters "--no-version-vectors" } to my build.gradle without adding generatedDensities = [] and it worksAneto
A
5

A previous answer to this question had a solution for developers who use Gradle, but I don't use Gradle so I want to summarize his answer which helped several people and what I eventually did. I accepted my own answer and not his since like I said, I don't use Gradle so I did not use what he wrote.

I did several things for it to work in the end. Possible solutions are:

First for Gradle users:

1) Revert the support library to an older version, since this one has a bug.

2) use compile 'com.android.support:appcompat-v7:23.2.1' as the bug was fixed there.

3) for Gradle Plugin 2.0:

android {  
    defaultConfig {  
        vectorDrawables.useSupportLibrary = true  
    }  
}

Or you can use Grade Build Tools 1.5.0 (classpath 'com.android.tools.build:gradle:1.5.0')

defaultConfig {
    generatedDensities = []
}

// no need for this with Gradle 2.0

aaptOptions {
    additionalParameters "--no-version-vectors"
}

This is the part for non Gradle users:

1) Open SDK manager.

2) Uninstalled both "Android Wear X" (where X is ARM or Intel) from APIs 22 and 23.

3) I then still had a compilation error in one of the styles of the AppCompat library. I simply commented them out (I'll risk the very specific device not working if it uses that very specific style).

After that I cleaned the project and it just started to work.

Apices answered 21/4, 2016 at 17:29 Comment(0)
H
3

For new users only, this problem is fixed in:

compile 'com.android.support:appcompat-v7:23.2.1'

Headwaiter answered 12/3, 2016 at 8:9 Comment(0)
H
3

I got this same error in Android Studio 2.2 after I updated my Gradle dependencies to the latest versions but forgot to update the buildToolsVersion of my project.

I changed:

    compile 'com.android.support:appcompat-v7:22.2.1'

to:

    compile 'com.android.support:appcompat-v7:24.2.1'

While buildToolsVersion remained at "22.0.1" like so:

    buildToolsVersion "22.0.1"

So all I did was to update the buildToolsVersion to 24 like so:

    buildToolsVersion "24"

since it has previously been downloaded with SDK Manager. So check the latest buildToolsVersion from SDK Manager and see if it matches the dependencies version.

Hope this helps someone.

Hahn answered 28/9, 2016 at 13:40 Comment(0)
D
3

Event after trying the already provided answers, the app was crashing on some devices (mainly Samsung). So along with that, I tried loading vector drawables like this

Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, R.drawable.resource_id);

This AppCompatDrawableManager internally tries to fetch drawable with various methods:

Drawable getDrawable(@NonNull Context context, @DrawableRes int resId,
            boolean failIfNotKnown) {
        checkVectorDrawableSetup(context);

        Drawable drawable = loadDrawableFromDelegates(context, resId);
        if (drawable == null) {
            drawable = createDrawableIfNeeded(context, resId);
        }
        if (drawable == null) {
            drawable = ContextCompat.getDrawable(context, resId);
        }

        if (drawable != null) {
            // Tint it if needed
            drawable = tintDrawable(context, resId, failIfNotKnown, drawable);
        }
        if (drawable != null) {
            // See if we need to 'fix' the drawable
            DrawableUtils.fixDrawable(drawable);
        }
        return drawable;
    }

Thus it works on all android versions and all devices (hopefully).

Note: Don't try to use Picasso(2.5.2)'s or Glide(3.7.0)'s method to load vector drawables. Because they internally use deprecated getDrawable(@DrawableRes int id) method. Which will result in Resources.NotFoundException on some devices.

Disallow answered 26/12, 2016 at 14:45 Comment(0)
A
0

For people like me still using Eclipse without Gradle, I had this error with Android Support Library r23.2.0 running on pre-Lollipop devices (API < 21).

This issue has been fixed in r23.2.1 and I have been able to run my project on API level 16 successfully.

This version of the library for Eclipse is not available through SDK Manager anymore, however you can manually download it from this link.

Adagio answered 29/8, 2017 at 14:1 Comment(0)
B
0

If the issue is in release app version. This solved for my release. I think because if you put shrinkResources true the drawable folders created does not have the drawable files.

    {
        ..
        minifyEnabled true
        shrinkResources false

    }
Blackboard answered 14/3, 2018 at 17:5 Comment(0)
B
0

I ran into this error when converting a few of my PNG files to SVG. It turns out that the issue was that I was loading a XML statelist. On Android API <= 23 the parser expects a viewportWidth/Height but a statelist doesn't have that.

So to fix it on these older Android's, I (besides enabling VectorCompat stuff), is to use a hardcoded statelist. Since I only need 1 statelist, it was not much effort, and now my SVG statelists work properly on Android 21.

 private Drawable createVectorButtonWithTheme(int theme) {
        if (Build.VERSION.SDK_INT <= 23) { //vector compat doesn't work with xml statelists somehow on 6.0 and lower
            return createVectorStateListWithTheme(theme);
        } else {
            ContextThemeWrapper themeWrapper = new ContextThemeWrapper(this, theme);
            Drawable vector = VectorDrawableCompat.create(getResources(), R.drawable.button, themeWrapper.getTheme());
            return vector;
        }
    }

    private StateListDrawable createVectorStateListWithTheme(int theme) {
        ContextThemeWrapper themeWrapper = new ContextThemeWrapper(this, theme);
        Drawable button = VectorDrawableCompat.create(getResources(), R.drawable.button_vector, themeWrapper.getTheme());
        Drawable button_pressed = VectorDrawableCompat.create(getResources(), R.drawable.button_vector_pressed, themeWrapper.getTheme());
        Drawable button_disabled = VectorDrawableCompat.create(getResources(), R.drawable.button_vector_disabled, themeWrapper.getTheme());
        StateListDrawable res = new StateListDrawable();
        res.addState(new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled}, button_pressed);
        res.addState(new int[]{android.R.attr.state_enabled}, button);
        res.addState(new int[]{}, button_disabled);
        return res;
    }
Baldachin answered 21/10, 2023 at 13:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.