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

こ雲淡風輕ζ 提交于 2019-12-10 17:29:32

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/31525853/robolectric-could-not-load-class-org-robolectric-shadows-shadowmultidex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!