nenick/android-gradle-template

A problem occurred evaluating project ':ComponentTestsRobolectric'

dawidgdanski opened this issue · 6 comments

Hey there,

Thanks a lot for sharing. Recently I've upgraded my Android Studio to the latest version (0.8.2) and today I've noticed your project on github. Unfortunately tests don't pass when I run them from script and I am given this error:

A problem occurred evaluating project ':ComponentTestsRobolectric'.

(class: com/novoda/gradle/test/SupportedLanguages, method: super$1$stream signature: ()Ljava/util/stream/Stream;) Illegal use of nonvirtual function call.

Particularily, it complains in this line:

android {
projectUnderTest ':AndroidSample'
}

Primarily I thought it was connected with java version but it's not.

Is this the Android Studio version issue? Is anyone familiar with this error? If so, how to get it working?

Thanks,
Dawid

This issue is most times related with a not compatible java version. like here http://jira.codehaus.org/browse/GROOVY-6550

Check which java version you use to compile. Then make sure that you use java 7. Neither java 6 nor java 8 will work with the used parts in this template.

Ok, works like a charm, thanks a lot!

I am also having this issue. In my case the project I'm testing is a library project. I can't seem to get past this error. Any suggestions?

Here is my test project gradle file:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
        classpath "com.novoda:gradle-android-test-plugin:0.9.9-SNAPSHOT"
    }
}

apply plugin: 'java'

test.reports.html.enabled = false     // just clean up dashboard from not generated reports
test.reports.junitXml.enabled = false // just clean up dashboard from not generated reports

apply plugin: 'android-test'
apply plugin: "jacoco"

android {
    projectUnderTest ':core'
}

dependencies {
    testCompile('junit:junit:4.11') {
        exclude module: 'hamcrest-core'
    }
    testCompile 'org.mockito:mockito-core:1.9.5'
    testCompile('org.robolectric:robolectric:2.3') {
        exclude module: 'classworlds'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-plugin-registry'
        exclude module: 'maven-profile'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'nekohtml'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-http-shared'
        exclude module: 'wagon-provider-api'
        exclude module: 'support-v4' // crazy but my android studio don't like this dependency and to fix it remove .idea and re import project
    }
    testCompile('com.squareup:fest-android:1.0.+') {
        exclude module: 'support-v4'
    }
}

apply from: '../scripts/jacoco-support.gradle'
apply from: '../scripts/android-studio-robolectric-support.gradle'

Here is my project under test:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:' + androidGradlePluginVersion
        classpath 'com.jakewharton.sdkmanager:gradle-plugin:' + sdkManagerPluginVersion
    }
}

apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.library'

final API_HOST = "\"http://api.shifton.us\"";

repositories {
    maven { url 'http://download.crashlytics.com/maven' }
}

android {
    compileSdkVersion projectCompileSdkVersion
    buildToolsVersion projectBuildToolsVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    defaultConfig {
        minSdkVersion projectMinSdkVersion
        targetSdkVersion projectTargetSdkVersion
        applicationId "com.shiftconnects.android.core"
        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }

    buildTypes {
        debug {
            buildConfigField "String", "API_HOST", API_HOST
        }
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            buildConfigField "String", "API_HOST", API_HOST
        }
    }

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

    lintOptions {
        abortOnError true
        disable 'InvalidPackage'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.crashlytics.android:crashlytics:1.+'
    compile 'com.android.support:support-v4:19.1.+'
    compile 'com.google.android.gms:play-services:5.0.77'
    compile 'com.squareup.retrofit:retrofit:1.6.1'
    compile 'com.squareup.retrofit:retrofit-mock:1.6.1'
    compile 'com.squareup.dagger:dagger:1.2.1'
    compile 'com.squareup.dagger:dagger-compiler:1.2.1'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
    compile 'com.squareup:tape:1.2.2'
    compile 'com.jakewharton:butterknife:5.1.1'
    compile 'org.apache.commons:commons-lang3:3.3'
    compile 'org.jetbrains:annotations:13.0'
    compile 'com.google.maps.android:android-maps-utils:0.3.1'
}

I don't understand your issue. If you have the same then set java 7 for your development environment and this error should be gone.

It still errors with Java 7 with the same error.

if you are sure that java 7 is used, then it must be something else.
you use sometimes java 8 or is it installed?
maybe recompile the novoda plugin with java 7?
provide a pull request for a simple library example, so that i can reproduce your issue?