Android studio createDebugCoverageReport上的gradlew ConnectedAndroidTest失败

Android studio createDebugCoverageReport上的gradlew ConnectedAndroidTest失败,android-studio,build.gradle,jacoco,gradlew,Android Studio,Build.gradle,Jacoco,Gradlew,运行.gradlew createCoverageReport时,出现以下错误: :WFMRecipeApplication:connectedAndroidTest Tests on Nexus 5 - 4.4.4 failed: Instrumentation run failed due to 'java.lang.VerifyError' 11:36:00 E/Device: Error during Sync: Remote object doesn't exist! null jav

运行.gradlew createCoverageReport时,出现以下错误:

:WFMRecipeApplication:connectedAndroidTest
Tests on Nexus 5 - 4.4.4 failed: Instrumentation run failed due to 'java.lang.VerifyError'
11:36:00 E/Device: Error during Sync: Remote object doesn't exist!
null
java.io.IOException: Failed to pull /data/data/com.project.recipes/coverage.ec from device
    at com.android.builder.testing.ConnectedDevice.pullFile(ConnectedDevice.java:115)
    at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:158)
    at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:42)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)
Caused by: com.android.ddmlib.SyncException: Remote object doesn't exist!
    at com.android.ddmlib.SyncService.pullFile(SyncService.java:314)
    at com.android.ddmlib.Device.pullFile(Device.java:873)
    at com.android.builder.testing.ConnectedDevice.pullFile(ConnectedDevice.java:108)
    ... 10 more
:WFMRecipeApplication:connectedAndroidTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':WFMRecipeApplication:connectedAndroidTest'.
> There were failing tests. See the report at: file:///Users/elidd1//connected/index.html
但是当我访问index.html时,它看起来是这样的:

我不明白它为什么会崩溃。。在此失败之前,构建将达到大约98%。我有一个运行4.4的nexus 5连接

我的build.gradle如下所示:

apply plugin: 'android'
apply plugin: 'jacoco'
android {
    compileSdkVersion 16
    buildToolsVersion '19.1.0'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 16
        versionCode 1
        versionName '0.7.2'
        testApplicationId "------.recipes.application.test"
        testInstrumentationRunner 'android.test.InstrumentationTestRunner'
    }
    signingConfigs {
        debug {
            storeFile file('../keystore/WFM_debug.jks')
            storePassword 'wfmrecipes'
            keyAlias 'WFMRecipes'
            keyPassword 'wfmrecipes'
        }
        release {
            storeFile file('../keystore/WFM_release.jks')
            storePassword 'wfmrecipes'
            keyAlias 'WFMRecipes'
            keyPassword 'wfmrecipes'
        }
    }
    buildTypes {
        release {
            runProguard true
            zipAlign true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.release
            resValue "bool", "isCrittercismEnabled", "true"
            resValue "bool", "isHockeyEnabled", "true"
            testCoverageEnabled true

        }
        debug {
            runProguard false
            zipAlign true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.debug
            resValue "bool", "isCrittercismEnabled", "false"
            resValue "bool", "isHockeyEnabled", "false"
            testCoverageEnabled true

        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    sourceSets {
        main { res.srcDirs = ['src/main/res', 'src/main/res/drawable', 'src/main/res/menu'] }
    }
    productFlavors {
    }
    jacoco {
        toolVersion = "0.7.1.201405082137"
        reportsDir = file("$buildDir/customJacocoReportDir")
    }


}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':Project')
    compile project(':WFMStore')
}


buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://oss.sonatype.org/content/repositories/comnewrelic-1153' }
        maven { url 'https://oss.sonatype.org/content/repositories/comnewrelic-1154' }
    }
    dependencies {
    }
}
//apply plugin: 'newrelic'

repositories {
    mavenCentral()
    maven { url 'https://oss.sonatype.org/content/repositories/comnewrelic-1153' }
}

dependencies {
    compile 'com.android.support:appcompat-v7:19.+'
}
dependencies {
    compile 'com.newrelic.agent.android:android-agent:+'
}

// added to cut down on the number of methods for codecoverage (limit is 65,536 and playservices hogs most of this) - elidd1
def toCamelCase(String string) {
    String result = ""
    string.findAll("[^\\W]+") { String word ->
        result += word.capitalize()
    }
    return result
}

afterEvaluate { project ->
    Configuration runtimeConfiguration = project.configurations.getByName('compile')
    ResolutionResult resolution = runtimeConfiguration.incoming.resolutionResult
    // Forces resolve of configuration
    ModuleVersionIdentifier module = resolution.getAllComponents().find { it.moduleVersion.name.equals("play-services") }.moduleVersion

    String prepareTaskName = "prepare${toCamelCase("${module.group} ${module.name} ${module.version}")}Library"
    File playServiceRootFolder = project.tasks.find { it.name.equals(prepareTaskName) }.explodedDir

    Task stripPlayServices = project.tasks.create(name: 'stripPlayServices', group: "Strip") {
        inputs.files new File(playServiceRootFolder, "classes.jar")
        outputs.dir playServiceRootFolder
        description 'Strip useless packages from Google Play Services library to avoid reaching dex limit'

        doLast {
            copy {
                from(file(new File(playServiceRootFolder, "classes.jar")))
                into(file(playServiceRootFolder))
                rename { fileName ->
                    fileName = "classes_orig.jar"
                }
            }
            tasks.create(name: "stripPlayServices" + module.version, type: Jar) {
                destinationDir = playServiceRootFolder
                archiveName = "classes.jar"
                from(zipTree(new File(playServiceRootFolder, "classes_orig.jar"))) {
                    exclude "com/google/ads/**"
                    exclude "com/google/android/gms/analytics/**"
                    exclude "com/google/android/gms/games/**"
                    exclude "com/google/android/gms/plus/**"
                    exclude "com/google/android/gms/drive/**"
                    exclude "com/google/android/gms/ads/**"
                }
            }.execute()
            delete file(new File(playServiceRootFolder, "classes_orig.jar"))
        }
    }

    project.tasks.findAll { it.name.startsWith('prepare') && it.name.endsWith('Dependencies') }.each { Task task ->
        task.dependsOn stripPlayServices
    }
}
两件事

  • 要修复第一个错误“由于“java.lang.VerifyError”导致检测运行失败”,请将构建工具升级到21+。这是他们已经修复的android构建工具中的一个bug。万岁
  • 你不必应用jacoco插件,它是android gradle插件的一部分。您所需要的只是“testCoverageEnabled true”,它将创建您的.ec文件。据我所知,应用这个插件并没有什么坏处,但是让你的头脑了解jacoco已经在那里了这一事实是很有帮助的

  • “reportsDir”的覆盖可能不起作用,因此您还应该在“build/outputs/reports/coverage/debug/index.html”中查找报表。

    应用插件部分会导致测试无法运行。 正如Bill所说,gradle的最新版本中包含了jacoco,因此无需再应用它

    我的考试因此而中断。 删除该行修复了我的问题,我再次收到报告