private int prepare() throws IOException {
        int size = 0;

        for (NodeImpl first : firsts) {
            size += first.prepare(this);
        }
        {
            int a = 0;
            for (Map.Entry<String, Ns> e : nses.entrySet()) {
                Ns ns = e.getValue();
                if (ns == null) {
                    ns = new Ns(null, new StringItem(e.getKey()), 0);
                    e.setValue(ns);
                }
                if (ns.prefix == null) {
                    ns.prefix = new StringItem(String.format("axml_auto_%02d", a++));
                }
                ns.prefix = update(ns.prefix);
                ns.uri = update(ns.uri);
            }
        }

        size += nses.size() * 24 * 2;

        this.stringItems.addAll(resourceString);
        resourceString = null;
        this.stringItems.addAll(otherString);
        otherString = null;
        this.stringItems.prepare();
        int stringSize = this.stringItems.getSize();
        if (stringSize % 4 != 0) {
            stringSize += 4 - stringSize % 4;
        }
        size += 8 + stringSize;
        size += 8 + resourceIds.size() * 4;
        return size;
    }
a class to write android axml

@author <a href="mailto:pxb1988@gmail.com">Panxiaobo</a>
android/third_party/apkbuilder/src/main/java/pxb/android/axml/AxmlWriter.java