Problem:
After implementing Robolectric with Pushwoosh Android SDK 5.+, tests fail with the following stack trace:
java.lang.NoClassDefFoundError: Could not initialize class com.pushwoosh.location.internal.a at com.pushwoosh.location.geofencer.GeofenceReceiver.<init>(Unknown Source) at sun.reflect.GeneratedConstructorAccessor33.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.robolectric.util.ReflectionHelpers.callConstructor(ReflectionHelpers.java:321) at org.robolectric.internal.bytecode.ShadowImpl.newInstanceOf(ShadowImpl.java:20) at org.robolectric.shadow.api.Shadow.newInstanceOf(Shadow.java:35) at org.robolectric.shadows.ShadowApplication.registerBroadcastReceivers(ShadowApplication.java:138) at org.robolectric.shadows.ShadowApplication.bind(ShadowApplication.java:127) at org.robolectric.shadows.CoreShadowsAdapter.bind(CoreShadowsAdapter.java:71) at org.robolectric.android.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:107) at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:290) at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:203) at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:109) at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:36) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:63) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Solution:
The issue is caused by Robolectric trying to create a GeofenceReceiver, which just cannot exist before Pushwoosh is initialized.
You can workaround the issue by removing unnecessary receivers like described in this thread:
Comments
0 comments
Please sign in to leave a comment.