1

I got these multiple errors while doing the Module 7. Writing UI tests with Espresso of the Android Testing Code lab.

I am using Android Studio 3.0 and these are the errors I am getting when I try to run the test:

Gradle messages:

Information:Gradle tasks [:app:assembleProdDebug, :app:assembleProdDebugAndroidTest]
/Users/sudo/Projects/Android/Android-Codelabs/android-testing/app/src/androidTest/java/com/example/android/testing/notes/notes/AppNavigationTest.java
Error:(29, 33) error: package android.support.v4.widget does not exist
Error:(61, 28) error: cannot access AppCompatActivity
class file for android.support.v7.app.AppCompatActivity not found
Error:(62, 13) error: cannot infer type arguments for ActivityTestRule<>

/Users/sudo/Projects/Android/Android-Codelabs/android-testing/app/src/androidTest/java/com/example/android/testing/notes/notes/NotesScreenTest.java
Error:(31, 33) error: package android.support.v7.widget does not exist
Error:(47, 37) error: package com.google.common.base does not exist
Error:(47, 1) error: static import only from classes and interfaces
Error:(71, 9) error: cannot find symbol method checkArgument(boolean,String)

Error:(76, 58) error: cannot find symbol class RecyclerView
Error:(95, 29) error: type argument NotesActivity is not within bounds of type-variable T
where T is a type-variable:
T extends Activity declared in class ActivityTestRule

Error:(96, 13) error: cannot infer type arguments for ActivityTestRule<>
Error:Execution failed for task ':app:compileProdDebugAndroidTestJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED in 9s
Information:11 errors
Information:0 warnings
Information:See complete output in console

Here are my build.gradle files

root/build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

// Define versions in a single place
ext {
    // Sdk and tools
    minSdkVersion = 10
    targetSdkVersion = 25
    compileSdkVersion = 25
    buildToolsVersion = '25.0.2'

    // App dependencies
    supportLibraryVersion = '25.3.1'
    guavaVersion = '18.0'
    glideVersion = '3.6.1'
    junitVersion = '4.12'
    mockitoVersion = '1.10.19'
    powerMockito = '1.6.2'
    hamcrestVersion = '1.3'
    runnerVersion = '0.5'
    rulesVersion = '0.5'
    espressoVersion = '2.2.2'
}

app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.example.android.testing.notes"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        flavorDimensions "versionCode"

        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }

    buildTypes {
        debug {
            // Run code coverage reports by default on debug builds.
            // testCoverageEnabled = true
        }
    }

    // If you need to add more flavors, consider using flavor dimensions.
    productFlavors {
        mock {
            applicationIdSuffix = ".mock"
        }
        prod {

        }
    }

    // Remove mockRelease as it's not needed.
    android.variantFilter { variant ->
        if(variant.buildType.name.equals('release')
                && variant.getFlavors().get(0).name.equals('mock')) {
            variant.setIgnore(true);
        }
    }

    // Always show the result of every unit test, even if it passes.
    testOptions.unitTests.all {
        testLogging {
            events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
        }
    }
    buildToolsVersion '26.0.2'
}

/*
 Dependency versions are defined in the top level build.gradle file. This helps keeping track of
 all versions in a single place. This improves readability and helps managing project complexity.
 */
dependencies {
    // App's dependencies, including test
    compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:design:$rootProject.supportLibraryVersion"
    compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
    compile "com.google.guava:guava:$rootProject.guavaVersion"
    compile "com.github.bumptech.glide:glide:$rootProject.glideVersion"
    compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.ext.espressoVersion"

    // Dependencies for local unit tests
    testCompile "junit:junit:$rootProject.ext.junitVersion"
    testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
    testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
    testCompile "org.powermock:powermock-module-junit4:$rootProject.ext.powerMockito"
    testCompile "org.powermock:powermock-api-mockito:$rootProject.ext.powerMockito"

    // Android Testing Support Library's runner and rules
    androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion"
    androidTestCompile "com.android.support.test:rules:$rootProject.ext.rulesVersion"

    // Espresso UI Testing dependencies.
    androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"
    androidTestCompile "com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion"
    androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion"
}

/*
Resolves dependency versions across test and production APKs, specifically, transitive
dependencies. This is required since Espresso internally has a dependency on support-annotations.
*/
configurations.all {
    resolutionStrategy.force "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
}

/*
All direct/transitive dependencies shared between your test and production APKs need to be
excluded from the test APK! This is necessary because both APKs will contain the same classes. Not
excluding these dependencies from your test configuration will result in an dex pre-verifier error
at runtime. More info in this tools bug: (https://code.google.com/p/android/issues/detail?id=192497)
*/
configurations.compile.dependencies.each { compileDependency ->
    println "Excluding compile dependency: ${compileDependency.getName()}"
    configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
        configurations.androidTestCompile.exclude module: "${compileDependency.getName()}"
    }
}

What am I missing?

0 Answers0