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

查看:326
本文介绍了java.lang.NoClassDefFoundError:org / robolectric / internal / ShadowExtractor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

  testImplementation'org.robolectric:shadows-play-services:3.4-rc2'
testImplementation org.robolectric:robolectric:3.6.1
testImplementationcom.google.android.gms:play-services-auth:$ rootProject.ext.googlePlayServicesVersion// // robolectric影子虚假地需要这

我试过这个:

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

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

@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE,shadows = {ShadowGoogleApiAvailability.class})
公共抽象类BaseTest {
@在
之前public void setUp(){
final ShadowGoogleApiAvailability shadowGoogleApiAvailability $ b = Shadows.shadowOf(GoogleApiAvailability.getInstance());
final int expectedCode = ConnectionResult.SUCCESS;
shadowGoogleApiAvailability.setIsGooglePlayServicesAvailable(expectedCode);


$ / code>

但是,我的测试失败并出现这个奇怪的错误:

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

我在做什么错误,如何解决这个问题?

解决方案

Google Play服务shadow已被重命名为

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

根据 https://github.com/robolectric/robolectric/issues/3489 ,这是Robolectric 3.5.x应该使用的。请注意,官方文档 - http://robolectric.org/using-add-on-modules / - 尚未更新以反映此更改。


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

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.

这篇关于java.lang.NoClassDefFoundError:org / robolectric / internal / ShadowExtractor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆