Jacoco with Gradle 0.10.0:远程对象不存在

时间:2014-04-30 19:58:28

标签: android testing android-gradle jacoco build.gradle

更新2014年10月21日: 通过使用buildtools 21确认该问题已得到修复。

更新于2014年9月18日: issue's status已更新为FutureRelease

更新 我听说这可能不适用于Dagger,而且由于Espresso使用Dagger,它可能会引起一些问题。给Gradle团队一个bug was submitted


Google最近更新了他们的Gradle implementation to 0.10.0。他们现在提供的一件事是Jacoco支持。为此,他们提到了以下内容:

testCoverageEnabled = true

进入您的构建类型。现在当我运行Espresso测试时(使用connectedCheck),当我开始运行:connectedAndroidTest任务时,我收到错误:

Tests on HTC One - 4.2.2 - API 17 - 1080x1920 - 4.2.2 failed: Instrumentation run failed due to 'java.lang.VerifyError'
01:38:31 E/Device: Error during Sync: Remote object doesn't exist!
null
java.io.IOException: com.android.ddmlib.SyncException: Remote object doesn't exist!
at com.android.builder.testing.ConnectedDevice.pullFile(ConnectedDevice.java:114)
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.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
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:849)
at com.android.builder.testing.ConnectedDevice.pullFile(ConnectedDevice.java:107)
... 8 more
:connectedAndroidTest FAILED

以下是我在build.gradle文件中更改的部分:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:0.10.+'
        ...
    }
    ...
}

android {
    buildTypes {
        debug {
            testCoverageEnabled = true
            ...
        }
        ....
    }
    ...
}

为了让Jacoco工作,我需要更新任何其他build.gradle文件吗?

该错误提到了一个"远程对象"不存在。通常我将此归因于仿真器不同步,重启会修复它。但是我已经尝试过了,但它也没有用。任何想法错误试图告诉我什么?

1 个答案:

答案 0 :(得分:1)

试一试......

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

repositories {
    mavenCentral()
}
apply plugin: 'com.android.application'
apply plugin: 'jacoco'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1" // Must Require

    defaultConfig {
        applicationId "com.packagename" <Change it>
        minSdkVersion 11
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"

    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

    lintOptions {
        abortOnError false
    }

    buildTypes {
        debug {
            testCoverageEnabled true
        }
    }
}

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

jacoco {
    toolVersion = "0.7.1.201405082137"
}