Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio not recognizes Espresso imports

I am trying to write a test case using Espresso.

I am using Android Studio 1.5.1 (Stable channel), Gradle plugin 1.5, Gradle 2.7. The problem is that Android Studio doesn't recognize any import related to Espresso (and not only)enter image description here

So, I tried to clean the project, rebuild, invalidate cache and restart, but nothing.

I added these dependencies in my app module:

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'

I added the runner in defaultConfig:

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

I created the test suite class under androidTest folder:

enter image description here

What am I doing wrong please?

UPDATE

Here is (part) of my 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 {
        sourceCompatibility 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'
}
like image 332
Daniele Vitali Avatar asked Feb 18 '16 16:02

Daniele Vitali


1 Answers

Perhaps your Build Variant is on "release" mode. you have to change it to debug. enter image description here

like image 185
BoshRa Avatar answered Oct 08 '22 18:10

BoshRa