I added ViewPagerIndicator to my project (it’s an Android library project), and my tests work fine from IntelliJ, but fail when I run them from ANT. To be clear, only the test that is referencing classes from this Android Library project is failing, the rest are passing without any issue. I’m guessing something isn’t right in my build.xml? Anyone else run into this?
Here’s the stack trace:
java.lang.NoClassDefFoundError:
Lcom/viewpagerindicator/CirclePageIndicator;
com.google.inject.internal.util.$ComputationException:
java.lang.NoClassDefFoundError:
Lcom/viewpagerindicator/CirclePageIndicator; at
com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:553)
at
com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
at
com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
at
com.google.inject.internal.FailableCache.get(FailableCache.java:50)
at
com.google.inject.internal.MembersInjectorStore.get(MembersInjectorStore.java:65)
at
com.google.inject.internal.InjectorImpl.getMembersInjector(InjectorImpl.java:950)
at
com.google.inject.internal.InjectorImpl.getMembersInjector(InjectorImpl.java:957)
at
com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:943)
at
roboguice.inject.ContextScopedRoboInjector.injectMembersWithoutViews(ContextScopedRoboInjector.java:243)
at roboguice.activity.RoboActivity.onCreate(RoboActivity.java:78) at
com.mycompany.myproduct.activities.TutorialActivity.onCreate(TutorialActivity.java:36)
at
com.mycompany.myproduct.activities.TutorialActivityTest.setup(TutorialActivityTest.java:37)
at
com.xtremelabs.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:292)
I figured this out.
In the
junittask under thetesttarget in build.xml (I took the snippet from the AndroidIntellijStarter project on Github), you need to add aclasspathreference pointing to the classes.jar file that gets built for every library project you have included in your project.There might be a more elegant way to achieve this, but it’s what I came up with on short notice: