I am using KXmlParser in a Spock specification (no Robolectric) to parse Android strings.xml file. I intermittently get the following trace:
java.lang.NoSuchMethodError: java.lang.System.arraycopy([CI[CII)V
at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1509)
at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:1001)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:448)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:313)
Any idea what could be wrong?
Here are are my ext properties:
minSdkVersion = 19
targetSdkVersion = 26
compileSdkVersion = 26
buildToolsVersion = '26.0.2'
Here is the code snippet:
try (FileInputStream in = new FileInputStream("app/src/main/res/values/strings.xml")) {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(in, null);
AndroidStringResource resource = null;
int eventType = parser.getEventType();
while (eventType != parser.END_DOCUMENT) {
eventType = parser.next();
if (eventType == parser.START_TAG) {
if (parser.getName().equals("string")) {
resource = new AndroidStringResource();
resource.name = parser.getAttributeValue(null, "name");
resource.context = parser.getAttributeValue(null, "context");
String maxLengthStr = parser.getAttributeValue(null, "maxLength");
resource.maxLength = (maxLengthStr == null) ? -1 : Integer.parseInt(maxLengthStr);
}
} else if (eventType == parser.TEXT) {
if (resource != null) {
resource.value = parser.getText();
}
} else if (eventType == parser.END_TAG) {
if (parser.getName().equals("string")) {
if (!resourceNameToServerKeyMap.containsKey(resource.name)) {
androidStringResourceMap.put(resource.name, resource);
}
resource = null;
}
}
}
}
Note that I am adding custom XML attributes to elements in my strings.xml. Here is an example:
myapp
An MVCE reproduacble test case is avilable here.