Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Unit Tests - no such property: bootClasspath

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

while using com.android.tools.build:gradle:1.1.0-rc1.

Anyone else got stuck on that?

like image 539
Wojtek Erbetowski Avatar asked Feb 10 '15 14:02

Wojtek Erbetowski


2 Answers

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.

like image 188
Wojtek Erbetowski Avatar answered Oct 02 '22 18:10

Wojtek Erbetowski


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.

like image 39
Ely Avatar answered Oct 02 '22 20:10

Ely