java.lang.UnsatisfiedLinkError: org.apache.harmony.xml.ExpatParser.staticInitialize

123 views
Skip to first unread message

Mike Dunbar

unread,
Jul 16, 2015, 10:39:37 AM7/16/15
to robol...@googlegroups.com
I'm currently running into this:

-----
java.lang.UnsatisfiedLinkError: org.apache.harmony.xml.ExpatParser.staticInitialize(Ljava/lang/String;)V
at org.apache.harmony.xml.ExpatParser.staticInitialize(Native Method)
at org.apache.harmony.xml.ExpatParser.<clinit>(ExpatParser.java:576)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:314)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
at android.util.Xml.parse(Xml.java:84)
at com.wsi.android.weather.utils.settings.MapSkinParser.parse(MapSkinParser.java:54)
at com.wsi.android.weather.utils.settings.MapSkinSettings.<init>(MapSkinSettings.java:37)
at com.wsi.android.framework.settings.ConfigurationManager.createSkinSettings(ConfigurationManager.java:118)
at com.wsi.android.framework.settings.ConfigurationManager.createSkinSettingsFromXmlConfig(ConfigurationManager.java:170)
at com.wsi.android.framework.settings.ConfigurationManager.initApplicationAndSkinSettings(ConfigurationManager.java:44)
at com.wsi.android.weather.utils.InitializationGuardian.performAppInit(InitializationGuardian.java:87)
at com.wsi.android.weather.utils.InitializationGuardian.attemptInit(InitializationGuardian.java:67)
at com.wsi.android.weather.ui.MapApplication.onCreate(MapApplication.java:68)
at com.weather.Weather.app.FlagshipApplication.onCreate(FlagshipApplication.java:164)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:140)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.
------

According to JavaDoc, "the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native." In ExpatParser (android-22 SDK) I do see:

----

/**
* Initialize static resources.
*/
private static native void staticInitialize(String emptyString);

static {
staticInitialize("");
}
-------

Any ideas what I should do here? I tried including shadows-maps, mistakenly thinking that comm.wsi.android was Android code - not surprisingly, that didn't help.

Thanks,
Mike

Kanishk Tripathi

unread,
Jul 16, 2015, 12:29:40 PM7/16/15
to robol...@googlegroups.com
Currently, robolectric does not support native code written outside Android library. Any native method accessed outside android code or any native library import will give this error. 
As the JVM cannot find any library linked to the called native method, it gives this error.
If it's an external library, then you can create its mock instance. 
If this code is run during the application setup then mocking won't be possible since all the shadowing is done before the tests are run.  
Message has been deleted

Mike Dunbar

unread,
Aug 7, 2015, 3:07:09 PM8/7/15
to Robolectric
I'm finally getting back to trying to use Robolectric in testing our project. Kanishk said "Currently, robolectric does not support native code written outside Android library. Any native method accessed outside android code or any native library import will give this error.", but android.util.Xml is part of the Android library right? And this error is happening during application setup, so my questions are:

- Is this something Robolectric should be handling, but just isn't - like a bug?
- Can anyone suggest a work-around here? I can try using a different XML parsing library, but I may get some pushback on that, if it's going to increase our app download size.

Any help appreciated. Thanks!

Kanishk Tripathi

unread,
Aug 12, 2015, 10:44:07 AM8/12/15
to Robolectric
I believe it's this class may not have been handled by robolectric. Here the android.util.Xml is part of android but it's internally referring to a class in org.apache in your stack trace which has a native method.

Mike Dunbar

unread,
Aug 14, 2015, 10:02:44 AM8/14/15
to Robolectric
And is this something that should be handled by robolectric, since the class is in the android.util package? Should I file a bug?

If someone on the project could confirm, or steer me in the right direction that would be MUCH appreciated. Really, really, really wanna get rolling with unit testing using this tool.

Thanks!
Mike

Michael Grafton

unread,
Aug 14, 2015, 11:10:40 AM8/14/15
to robol...@googlegroups.com
This sounds like a legitimate issue. There's a similar issue here; the workaround posted in that thread is to avoid android.util.Xml.parse(). 

If that doesn't work, feel free to post an issue to GitHub.

Mike

--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages