Android Unit Tests - no such property: bootClasspath

前端 未结 3 738
逝去的感伤
逝去的感伤 2021-02-18 22:20

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

After caref

相关标签:
3条回答
  • 2021-02-18 22:34

    That Testing Support feature is experimental. That said maybe there is no quick solution to your issue or might be a bug.

    However, I would dig deeper into this, reading the message: This line Execution failed for task ':app:compileDebugGroovy'. mentions the task, so I would go and figure what that task does. I suppose it's a delivered task. The error being that in that task there is a property missing > No such property: bootClasspath for class: com.android.build.gradle.AppPlugin

    So maybe try to find that task and make sure the bootClasspath property is set for the AppPlugin class.

    0 讨论(0)
  • 2021-02-18 22:48

    Try to upgrade to the new version (RC3)

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0-rc3'
        // ..
    }
    

    You can also take a look here in order to compare your current setup with a working example.

    0 讨论(0)
  • 2021-02-18 22:49

    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.

    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)
    }
    

    and definition of RUNTIMEJARS_COMPAT:

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

    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();
    ...
    

    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.

    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.

    Let's wait then.

    0 讨论(0)
提交回复
热议问题