在Dalvik的运行设备上运行的长者preSSO仪器测试问题 [英] Issues running Espresso instrument tests on Dalvik runtime devices

查看:173
本文介绍了在Dalvik的运行设备上运行的长者preSSO仪器测试问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我过类似的问题,运行<一href="http://stackoverflow.com/questions/5561353/fragmentactivity-can-not-be-tested-via-activityinstrumentationtestcase2">FragmentActivity不能通过ActivityInstrumentationTestCase2 的测试

I'm running across a similar issue to FragmentActivity can not be tested via ActivityInstrumentationTestCase2

与顶级解决方案的问题也只适用于使用Eclipse构建系统。我使用的摇篮我的项目。

The problem with the top solution there is that only applies to using the Eclipse build system. I'm using Gradle for my project.

在我的Nexus 5运行ART运行时,我居preSSO仪器测试完美运行。当我使用的Nexus 4上的Dalvik运行时或模拟器,我跑的测试框架外运行应用程序时不会出现异常。

On my Nexus 5 running the ART runtime, my Espresso instrument tests run perfectly. When I use a Nexus 4 on the Dalvik runtime or an emulator, I run into an exception that doesn't occur when running the app outside of the testing framework.

java.lang.NoClassDefFoundError: com.packagename.fragment.ProgressDialogFragment

在日志中,我发现类似链接的问题,这些可疑邮件:

In the logs, I find these suspicious messages similar to the linked question:

Class resolved by unexpected DEX: Landroid/support/v4/app/DialogFragment2;(0x41e969d8):0x76064000 ref [Landroid/support/v4/app/DialogFragment;] Landroid/support/v4/app/DialogFragment;(0x41e969d8):0x75883000
(Landroid/support/v4/app/DialogFragment2; had used a different Landroid/support/v4/app/DialogFragment; during pre-verification)
Unable to resolve superclass of Landroid/support/v4/app/DialogFragment2; (271)
Link of class 'Landroid/support/v4/app/DialogFragment2;' failed
Unable to resolve superclass of Lcom/packagename/fragment/ProgressDialogFragment; (270)
Link of class 'Lcom/packagename/fragment/ProgressDialogFragment;' failed
Could not find method com.packagename.fragment.ProgressDialogFragment.newInstance, referenced from method com.packagename.activity.IntroActivity.doJoin
VFY: unable to resolve static method 47365: Lcom/packagename/fragment/ProgressDialogFragment;.newInstance (I)Landroid/support/v4/app/DialogFragment2;
VFY: replacing opcode 0x71 at 0x0063

ProgressDialogFragment DialogFragment2 的子类,这是一个子类的支持A​​ndroid库的 DialogFragment

ProgressDialogFragment is a subclass of DialogFragment2 which is a subclass of the Android support library's DialogFragment class

下面是我的摇篮文件的依赖关系是否有帮助:

Here are the dependencies in my Gradle file if that helps:

    compile 'com.android.support:support-v4:+'
    compile 'com.android.support:appcompat-v7:+'

    compile 'com.google.android.gms:play-services:+'

    compile 'com.google.code.findbugs:jsr305:+'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.3.+'
    compile 'de.greenrobot:greendao:1.3.+'

    compile 'fr.avianey:facebook-android-api:+@aar'

    compile 'com.squareup.mimecraft:mimecraft:1.1.+'
    compile 'com.squareup.picasso:picasso:2.2.+'
    compile 'com.squareup.okhttp:okhttp:1.5.+'

    compile 'eu.inmite.android.lib:android-styled-dialogs:1.1.+@aar'

    compile 'com.newrelic.agent.android:android-agent:3.+'

    compile 'uk.co.chrisjenx:calligraphy:0.7.+'

    compile 'com.github.chrisbanes.actionbarpulltorefresh:library:0.9.+'
    compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:0.9.+'

    apt "com.jakewharton:butterknife:${project.ext.butterKnifeVersion}"
    compile "com.jakewharton:butterknife:${project.ext.butterKnifeVersion}"

    compile fileTree(dir: 'libs', include: '*.jar')

    // Excluded modules were determined from here: https://github.com/robolectric/deckard-gradle
    instrumentTestCompile fileTree(dir: 'libs-test', include: '*.jar')
    instrumentTestCompile 'com.google.guava:guava:14.0.1',
            'com.squareup.dagger:dagger:1.1.0',
            'org.hamcrest:hamcrest-integration:1.1',
            'org.hamcrest:hamcrest-core:1.1',
            'org.hamcrest:hamcrest-library:1.1'

    instrumentTestCompile('junit:junit:4.11') {
        exclude module: 'hamcrest-core'
    }
    instrumentTestCompile('org.robolectric:robolectric:2.3-SNAPSHOT') {
        exclude module: 'classworlds'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-plugin-registry'
        exclude module: 'maven-profile'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'nekohtml'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-http-shared'
        exclude module: 'wagon-provider-api'
    }
    instrumentTestCompile 'org.mockito:mockito-core:1.9.+'

所以我的问题是我怎么能确保同样的支持库被应用APK和测试APK之间使用?我已经尝试过在 instrumentTestCompile加入com.android.support:support-v4:+。,以确保相同的支持库版本,但没有帮助

So my question is how can I make sure that the same support library is being used between the application APK and the test APK? I've already tried adding in instrumentTestCompile 'com.android.support:support-v4:+' to ensure the same support library version but that didn't help.

推荐答案

在太多的痛苦,汗水和泪水。我设法确定解决方案。简单地增加排除组:com.android.support',模块:支持-V4来排除对Robolectric的列表中允许Robolectric继续,而有其无法正常工作崩溃的Dalvik的运行。

After much pain, sweat and tears. I managed to determine the solution. Simply adding exclude group: 'com.android.support', module: 'support-v4' to the list of excludes for Robolectric allowed Robolectric to continue to work while having it not crash on the Dalvik runtime.

这篇关于在Dalvik的运行设备上运行的长者preSSO仪器测试问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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