0

I'm playing with the new vector xml drawables on older platforms like Kitkat or Gingerbread. I have an image like this:

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="300dp"
        android:height="300dp"
        android:viewportWidth="300"
        android:viewportHeight="300">
    <group>
        <path
            android:fillColor="@color/primary"
            android:pathData="@string/svg_path_background" />
        <path
            android:fillColor="#fff"
            android:pathData="@string/svg_path1" />
        <path
            android:fillColor="@color/primary"
            android:pathData="@string/svg_path2" />
    </group>
</vector>

The exact values don't matter, that works fine on Lollipop. However I try now to read this xml file (from the drawable directory). This works fine, except that in every tag one attribute is missing. I have no clue why this happens:

public static void load(Resources res, int drawable) {
    XmlResourceParser vector = res.getXml(drawable);
    int type = -1;
    StringBuilder xml = new StringBuilder();
    while(type != XmlResourceParser.END_DOCUMENT) {
        try {
            type = vector.getEventType();
            switch(type) {
            case XmlResourceParser.START_TAG:
                xml.append("<");
                xml.append(vector.getName());
                for(int i = 0; i < vector.getAttributeCount(); i++) {
                    xml.append(" ");
                    xml.append(vector.getAttributeName(i));
                    xml.append("=\"");
                    xml.append(vector.getAttributeValue(i));
                    xml.append("\"");
                }
                xml.append(">\n");
                break;
            case XmlResourceParser.END_TAG:
                xml.append("</");
                xml.append(vector.getName());
                xml.append(">\n");
                break;
            }
            vector.next();
        } catch(XmlPullParserException | IOException e) {
            e.printStackTrace();
        }
    }
    Log.d("XML-Test", xml.toString());
    vector.close();
}

The output of this code above is this here on Kitkat and Gingerbread:

<vector height="300.0dip" width="300.0dip" viewportHeight="300.0">
<group>
<path pathData="@2131624234">
</path>
<path pathData="@2131624248">
</path>
<path pathData="@2131624249">
</path>
</group>
</vector>

And the correct output on Lollipop:

<vector height="300.0dip" width="300.0dip" viewportWidth="300.0" viewportHeight="300.0">
<group>
<path fillColor="@2131296323" pathData="@2131624234">
</path>
<path fillColor="#ffffffff" pathData="@2131624248">
</path>
<path fillColor="@2131296323" pathData="@2131624249">
</path>
</group>
</vector>

Is it possible that this is a bug of the build system? I don't get how the differnt outputs are possible. I'm using AS 1.0.2 with buildToolsVersion 21.1.2

4

1 回答 1

0

这似乎是 Android 构建工具的一个错误,也检查这个错误报告

于 2015-01-19T10:23:04.880 回答