简体   繁体   English

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

[英]java.lang.NoClassDefFoundError: org/robolectric/internal/ShadowExtractor

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? 我做错了什么,该如何解决?

The Google Play Services shadow has been renamed to Google Play服务影子已重命名为

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. 根据https://github.com/robolectric/robolectric/issues/3489 ,这就是Robolectric 3.5.x应该使用的方式。 Note that the official docs - http://robolectric.org/using-add-on-modules/ - is not yet updated to reflect this change. 请注意,官方文档-http: //robolectric.org/using-add-on-modules/-尚未更新以反映此更改。

This was deprecated and removed. 不推荐使用并删除它。 Switch to Shadows.extract() . 切换到Shadows.extract() Refer to this issue 参考这个问题

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android批注,gradle和robolectric:java.lang.NoClassDefFoundError:org / androidannotations / api / view / HasViews - android annotations, gradle and robolectric: java.lang.NoClassDefFoundError: org/androidannotations/api/view/HasViews Robolectric PowerMock运行测试时出现java.lang.NoClassDefFoundError错误 - Robolectric PowerMock java.lang.NoClassDefFoundError error while running a test 包含Robolectric时在Espresso Test上的java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError on Espresso Test when including Robolectric 引起:java.lang.NoClassDefFoundError: org/gradle/internal/impldep/com/google/common/collect/Lists - Caused by: java.lang.NoClassDefFoundError: org/gradle/internal/impldep/com/google/common/collect/Lists java.lang.NoClassDefFoundError:org.apache.commons.lang3.ArrayUtils - java.lang.NoClassDefFoundError: org.apache.commons.lang3.ArrayUtils Robolectric:java.lang.RuntimeException:java.lang.ClassNotFoundException:org.robolectric.android.internal.ParallelUniverse - Robolectric: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.robolectric.android.internal.ParallelUniverse java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM