java.lang.NoClassDefFoundError: org/robolectric/internal/ShadowExtractor

穿精又带淫゛_ 提交于 2019-12-24 23:03:37

问题


Using

testImplementation 'org.robolectric:shadows-play-services:3.4-rc2'
testImplementation "org.robolectric:robolectric:3.6.1"
testImplementation "com.google.android.gms:play-services-auth:$rootProject.ext.googlePlayServicesVersion" // the robolectric shadow bogusly needs this

I am trying this:

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;

import org.junit.Before;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.gms.Shadows;
import org.robolectric.shadows.gms.common.ShadowGoogleApiAvailability;

@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, shadows = {ShadowGoogleApiAvailability.class})
public abstract class BaseTest {
        @Before
        public void setUp() {
                final ShadowGoogleApiAvailability shadowGoogleApiAvailability
                        = Shadows.shadowOf(GoogleApiAvailability.getInstance());
                final int expectedCode = ConnectionResult.SUCCESS;
                shadowGoogleApiAvailability.setIsGooglePlayServicesAvailable(expectedCode);
        }
}

however, my tests are failing with this weird error:

java.lang.NoClassDefFoundError: org/robolectric/internal/ShadowExtractor
    at org.robolectric.shadows.gms.Shadows.shadowOf(Shadows.java:37)
    at ......BaseTest.setUp(BaseTest.java:19)

What am I doing wrong, how to fix this?


回答1:


The Google Play Services shadow has been renamed to

testImplementation 'org.robolectric:shadows-playservices:3.6.1'

according to https://github.com/robolectric/robolectric/issues/3489 and this is what should be used with Robolectric 3.5.x. Note that the official docs - http://robolectric.org/using-add-on-modules/ - is not yet updated to reflect this change.




回答2:


This was deprecated and removed. Switch to Shadows.extract(). Refer to this issue

https://github.com/robolectric/robolectric/issues/3339



来源:https://stackoverflow.com/questions/48123570/java-lang-noclassdeffounderror-org-robolectric-internal-shadowextractor

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