ResXmlPatcher.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:AndroidApktool 作者:
/**
 * Any @string reference in a <provider> value in AndroidManifest.xml will break on
 * build, thus preventing the application from installing. This is from a bug/error
 * in AOSP where public resources cannot be part of an authorities attribute within
 * a <provider> tag.
 *
 * This finds any reference and replaces it with the literal value found in the
 * res/values/strings.xml file.
 *
 * @param file File for AndroidManifest.xml
 * @throws AndrolibException
 */
public static void fixingPublicAttrsInProviderAttributes(File file) throws AndrolibException {
    if (file.exists()) {
        try {
            Document doc = loadDocument(file);
            XPath xPath = XPathFactory.newInstance().newXPath();
            XPathExpression expression = xPath.compile("/manifest/application/provider");

            Object result = expression.evaluate(doc, XPathConstants.NODESET);
            NodeList nodes = (NodeList) result;

            for (int i = 0; i < nodes.getLength(); i++) {
                Node node = nodes.item(i);
                NamedNodeMap attrs = node.getAttributes();

                if (attrs != null) {
                    Node provider = attrs.getNamedItem("android:authorities");

                    if (provider != null) {
                        String reference = provider.getNodeValue();
                        String replacement = pullValueFromStrings(file.getParentFile(), reference);

                        if (replacement != null) {
                            provider.setNodeValue(replacement);
                            saveDocument(file, doc);
                        }
                    }
                }
            }

        }  catch (SAXException | ParserConfigurationException | IOException |
                XPathExpressionException | TransformerException ignored) {
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号