private static String getAndroidPrefix(Element xml) { String toolsPrefix = XmlUtils.lookupNamespacePrefix( xml, SdkConstants.ANDROID_URI, SdkConstants.ANDROID_NS_NAME, false); if (!toolsPrefix.equals(SdkConstants.ANDROID_NS_NAME) && xml.getOwnerDocument().getDocumentElement().getAttribute("xmlns:" + toolsPrefix) == null) { // this is weird, the document is using "android" prefix but it's not bound // to our namespace. Add the proper xmlns declaration. xml.setAttribute("xmlns:" + toolsPrefix, SdkConstants.ANDROID_URI); } return toolsPrefix; }