Android的单元测试 - 没有这样的属性:BOOTCLASSPATH [英] Android Unit Tests - no such property: bootClasspath

查看:505
本文介绍了Android的单元测试 - 没有这样的属性:BOOTCLASSPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行一个简单的测试案例为Android在刚宣布的单元测试的支持 - <一个href="http://tools.android.com/tech-docs/unit-testing-support">http://tools.android.com/tech-docs/unit-testing-support

I'm trying to execute a simple test case for Android following just announced unit testing support - http://tools.android.com/tech-docs/unit-testing-support

在认真地按照演练我试图运行 ./ gradlew测试。 我得到这个错误:

After carefully following the walkthrough I'm trying to run ./gradlew test. I'm getting this error:

Execution failed for task ':app:compileDebugGroovy'.
> No such property: bootClasspath for class: com.android.build.gradle.AppPlugin

在使用 com.android.tools.build:gradle:1.1.0-rc1

任何人就死在这?

推荐答案

问题是,Groovy Android的摇篮插件(有Groovy的工作在Android)不是简单的工作与Android插件版本 1.1 .0 RCX

The problem is that Groovy Android Gradle plugin (to have Groovy working on Android) isn't simply working with Android plugin in version 1.1.0-rcX.

下面是一个非常有趣的一件code直接从 groovyx.grooid.GroovyAndroidPlugin 版本 0.3.5 (目前最新的,这里的<一个href="https://github.com/groovy/groovy-android-gradle-plugin/blob/master/src/main/groovy/groovyx/grooid/GroovyAndroidPlugin.groovy#L123">source)

Here's a very interesting piece of code directly from groovyx.grooid.GroovyAndroidPlugin, version 0.3.5 (current latest, here's the source)

    def getRuntimeJars(Project project, plugin) {
    int index
    switch (getAndroidPluginVersion(project)) {
        case ~/0\.9\..*/:
            index = 0
            break
        case ~/0\.10\..*/:
        case ~/0\.11\..*/:
        case ~/0\.12\..*/:
        case ~/0\.13\..*/:
        case ~/0\.14\..*/:
        case ~/1\.0\..*/:
            index = 1
            break
        default:
            index = RUNTIMEJARS_COMPAT.size()-1
    }
    def fun = RUNTIMEJARS_COMPAT[index]
    fun(plugin)
}

和定义 RUNTIMEJARS_COMPAT

private static List RUNTIMEJARS_COMPAT = [
        { it.runtimeJars },
        { it.bootClasspath }
]

所以该API必须在Android的摇篮之间的已经改变了0.9.x版本 0.10.0 (是的,我知道 - 那些谷歌开发者改变一切有:[)。因此,让我们来看看在Android插件版本的问题,使类 1.0.0

So that API must have changed in Android Gradle between 0.9.x and 0.10.0 (yeah, I know - those Google devs change everything there :[ ). So let's take a look at that problem making class in Android Plugin version 1.0.0:

> javap -cp [path to proper jar] com.android.build.gradle.AppPlugin:

public class com.android.build.gradle.AppPlugin extends com.android.build.gradle.BasePlugin implements org.gradle.api.Plugin<org.gradle.api.Project> {
...
public java.util.List super$2$getBootClasspath();
...

是啊!还有我们所需要的方法(从父 com.android.build.gradle.BasePlugin 类来了)。现在有没有像在版本 1.1.0-RC3 。更重要的是,的API com.android.build.gradle.AppPlugin 就完全变了,所以它不是简单的事如果(版本)来解决这个问题。

Yup! There's the method we need (coming from parent com.android.build.gradle.BasePlugin class). Now there's nothing like that in version 1.1.0-rc3. What's more, the API of com.android.build.gradle.AppPlugin is completely changed, so it's not a matter of simple if(version) to fix that.

我想有没有机会,有Groovy的Andr​​oid的摇篮插件在单元测试工作(因为 1.1.0 ),直到作者更新插件。

I guess there's no chance to have Groovy Android Gradle plugin working with Unit Tests (since 1.1.0) until authors update the plugin.

让我们拭目以待呢。

这篇关于Android的单元测试 - 没有这样的属性:BOOTCLASSPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆