Android Instrumentation Test Java.lang.unsatisfiedlinkerror On Using Androidjunitrunner And Androidjunit4
Solution 1:
Found the fix for this. We were not using zendesk code in our test cases. The broadcast receivers from the added dependency(zendesk) were getting added to AndroidManifest.xml through the gradle build. The RobolectricTestRunner class parses the manifest into its internal ApplicationManifest object and then sets up application state through ShadowApplication class. The ShadowApplication class registers broadcast receivers from the application manifest. This is where I was getting the above error.
Fix: We have a custom test runner that extends RobolectricGradleTestRunner. In that I have overriden the getAppManifest method and removed the broadcast receivers not required. I know its a kind of workaround but there was no other alternative. Didn't want to create another manifest and create duplication. Here's the code snippet.
@OverrideprotectedAndroidManifestgetAppManifest(org.robolectric.annotation.Config config) {
AndroidManifest manifest = super.getAppManifest(config);
List<BroadcastReceiverData> broadcastReceivers = manifest.getBroadcastReceivers();
List<BroadcastReceiverData> removeList = newArrayList<>();
for(BroadcastReceiverData receiverData : broadcastReceivers) {
if(isDeletePackage(receiverData.getClassName())) {
removeList.add(receiverData);
}
}
broadcastReceivers.removeAll(removeList);
return manifest;
}
privatebooleanisDeletePackage(String className) {
for(String s : DELETE_BROADCAST_PACKAGE) {
if(className.startsWith(s)) {
returntrue;
}
}
returnfalse;
}
The DELETE_BROADCAST_PACKAGE is simply a String hashset. Containing the package hierarchy name
Post a Comment for "Android Instrumentation Test Java.lang.unsatisfiedlinkerror On Using Androidjunitrunner And Androidjunit4"