在createDebugCoverageReport上使用gradlew connectedAndroidTestFails

时间:2014-09-26 16:00:37

标签: 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
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时它看起来像这样: enter image description here

我不明白它崩溃的原因......在此失败之前,构建达到了大约98%。我有一个nexus 5连接运行4.4 ..

我的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
    }
}

2 个答案:

答案 0 :(得分:0)

夫妻俩。

  1. 要修复第一个错误“由于'java.lang.VerifyError'导致检测运行失败”,请将构建工具升级到21+。这是他们修复的android构建工具中的一个错误。万岁!
  2. 您不必应用jacoco插件,它是android gradle插件的一部分。您只需要'testCoverageEnabled true',它将创建您的.ec文件。据我所知,应用这个插件并没有什么坏处,但是你可以了解jacoco已经存在的事实。
  3. 'reportsDir'的覆盖可能不起作用,因此您还应该在'build / outputs / reports / coverage / debug / index.html'中查找报告。

答案 1 :(得分:0)

apply插件部分导致测试无法运行。 就像比尔建议gradle的最新版本已经打​​包jacoco所以它不再适用。

我的测试最近因此而破产。 删除该行修复了我的问题,我再次收到报告。