Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robolectric - Could not load class: org.robolectric.shadows.ShadowMultiDex

I am configuring Robolectric for a project that uses multi dex. I am using Robolectric 3.0 RC3 which should support Multidex without throwing that "Multi dex installation failed" exception.

testCompile('org.robolectric:robolectric:3.0-rc3')

My sample test is in src/test/java/SandwichTest:

@RunWith(RobolectricGradleTestRunner.class)
public class SandwichTest {
  @Test
  public void firstTest() { }
}

I have a global configuration file to load ShadowMultiDex in src/test/resources called robolectric.properties per the instructions on the Robolectric site:

shadows=org.robolectric.shadows.ShadowMultiDex

When I run my sample SandwichTest, I get this exception:

Could not load class: org.robolectric.shadows.ShadowMultiDex
java.lang.RuntimeException: Could not load class: org.robolectric.shadows.ShadowMultiDex
at org.robolectric.annotation.Config$Implementation.parseClass(Config.java:147)

It looks like Robolectric is finding my configuration file but is unable to load the ShadowMultiDex class. Attempting to add the shadow multi dex module to my gradle file manually:

 testCompile('org.robolectric:shadows-multidex:3.0-SNAPSHOT')

or

 testCompile('org.robolectric:shadows-multidex')

Causes "failed to resolve" issues during sync.

What steps am I missing to get this sample test to run?

like image 820
Mark Avatar asked Feb 09 '23 12:02

Mark


1 Answers

In your question, I noticed you were missing a version on your Gradle dependency.

You have:

testCompile('org.robolectric:shadows-multidex')

You need:

testCompile('org.robolectric:shadows-multidex:3.0')

Actual Release: https://oss.sonatype.org/content/repositories/releases/org/robolectric/shadows-multidex/

You should remove the:

shadows=org.robolectric.shadows.ShadowMultiDex

from your src/test/resources/robolectric.properties file. That is used for custom Shadows.

like image 104
Jared Burrows Avatar answered Apr 29 '23 20:04

Jared Burrows