Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android Studio无法识别Espresso导入大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用Espresso编写测试用例.

我使用的是Android studio 1.5.1(稳定频道),Gradle插件1.5,Gradle 2.7.
问题是Android studio无法识别与Espresso(而不仅仅是)相关的任何导入

所以,我试图清理项目,重建,使缓存无效并重新启动,但没有.

我在我的app模块中添加了这些依赖项:

androidTESTCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTESTCompile 'com.android.support:support-Annotations:23.1.1'
androidTESTCompile 'com.android.support.test:runner:0.4.1'
androidTESTCompile 'com.android.support.test:rules:0.4.1'

我在defaultConfig添加了runner:

testinstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

在AndroidTest文件夹下创建了测试套件类:

我做错了什么?

updatE

这是我的build.gradle的(部分):

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 5
        versionName '1.4'

        testinstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    compiLeoptions {
        @R_618_9016@eCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    buildTypes {
        //my build type configs
    }

    packagingOptions {
        exclude 'Meta-INF/services/javax.Annotation.processing.Processor'
        exclude 'Meta-INF/LICENSE'
        exclude 'Meta-INF/LICENSE.txt'
        exclude 'Meta-INF/NOTICE'
        exclude 'Meta-INF/NOTICE.txt'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    dexOptions {
        incremental true
        preDexLibraries = false
        jumboMode = false
        javaMaxHeapSize "2g"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'],dir: 'libs')
    compile 'com.viewpagerinDicator:library:2.4.1'
    compile project(':libraries:rITracking')
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-Annotations:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:gridlayout-v7:23.1.1'
    compile 'com.google.code.gson:gson:2.5'
    compile 'com.google.android.gms:play-services-plus:8.4.0'
    compile 'com.google.android.gms:play-services-base:8.4.0'
    compile 'de.greenrobot:eventbus:2.4.1'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp:2.7.2'
    compile 'com.facebook.android:facebook-android-sdk:4.9.0'
    compile 'com.cocosw:bottomsheet:1.2.0@aar'                          //Bottom Sheet that implement material design used for ShareDialog
    compile 'com.github.bumptech.glide:glide:3.6.1'                     //Glide library
    compile 'com.googlecode.libphonenumber:libphonenumber:7.2.3'        //Library used to parse/merge phones number to E164 format
    compile 'me.Leolin:ShortcutBadger:1.1.3@aar'                        //Used to show badge on application icon,library is optimized to work on most of devices
    compile 'com.Stripe:Stripe-android:1.0.3'                              //Stripe payment gateway,used to integrate credit card payment
    provided 'org.projectlombok:lombok:1.16.6'
    apt "org.projectlombok:lombok:1.16.6"
    compile 'com.jakewharton:butterknife:7.0.1'
    apt "com.jakewharton:butterknife:7.0.1"
    compile 'de.greenrobot:greendao:2.1.0'                              //Green Dao library is ORM implementation for Android sql lite
    compile files('libs/libAMMsdk.jar')
    compile files('libs/apptimize-android-2.9.1.jar')

    TESTCompile 'junit:junit:4.12'

    androidTESTCompile "com.android.support:support-Annotations:23.1.1"
    androidTESTCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTESTCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
    androidTESTCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
        exclude group: 'com.android.support',module: 'appcompat'
        exclude group: 'com.android.support',module: 'support-v4'
        exclude module: 'recyclerview-v7'
    }
    androidTESTCompile 'com.android.support.test:runner:0.4.1'
    androidTESTCompile 'com.android.support.test:rules:0.4.1'
}

解决方法

更新2016年11月30日

就像@Jaymes Bearden在下面的评论中所说的那样.

使用TESTBuildType. Android studio 2.2,gradle 2.2.2

android {
        TESTBuildType "yourBuildType"
}

老答复

我发现不是解决方案,而是一些问题的根源.在我的项目中,我有很多BuildTypes.特别是多个调试版本.

一切都只在认的调试版本类型中有效.我认为这是一些内部Android studio错误.

我的AS版本 – 2.1

大佬总结

以上是大佬教程为你收集整理的Android Studio无法识别Espresso导入全部内容,希望文章能够帮你解决Android Studio无法识别Espresso导入所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。