mirror of
https://github.com/revanced/Apktool.git
synced 2024-12-04 18:12:54 +01:00
Fix APKs with SDK versions being reference values
This non-standard behavior is rare, but quite annoying. The solution is simple - replacing the reference value with the actual value from integers.xml, just like Apktool already does for versionName.
This commit is contained in:
parent
be1aea76fe
commit
49e55f522f
@ -197,6 +197,41 @@ public final class ResXmlPatcher {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds key in integers.xml file and returns text value
|
||||
*
|
||||
* @param directory Root directory of apk
|
||||
* @param key Integer reference (ie @integer/foo)
|
||||
* @return String|null
|
||||
* @throws AndrolibException
|
||||
*/
|
||||
public static String pullValueFromIntegers(File directory, String key) throws AndrolibException {
|
||||
if (key == null || ! key.contains("@")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File file = new File(directory, "/res/values/integers.xml");
|
||||
key = key.replace("@integer/", "");
|
||||
|
||||
if (file.exists()) {
|
||||
try {
|
||||
Document doc = loadDocument(file);
|
||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||
XPathExpression expression = xPath.compile("/resources/integer[@name=" + '"' + key + "\"]/text()");
|
||||
|
||||
Object result = expression.evaluate(doc, XPathConstants.STRING);
|
||||
|
||||
if (result != null) {
|
||||
return (String) result;
|
||||
}
|
||||
|
||||
} catch (SAXException | ParserConfigurationException | IOException | XPathExpressionException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes attributes like "versionCode" and "versionName" from file.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user