Search code examples
androidgradlegroovyspockandroid-jack-and-jill

Problems running Android app with Spock and Java 8


Here is my set up. I have an Android project with a couple of Java (not Android) modules.

Recently I started using Spock (which is a testing framework based on JUnit and Groovy).

On the Java modules I simply use the groovy plugin like this:

apply plugin: 'groovy'

And then include these dependencies:

dependencies {
  testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
  testCompile 'org.codehaus.groovy:groovy-all:2.4.6'
  testCompile 'cglib:cglib-nodep:3.1'
  testCompile 'org.objenesis:objenesis:2.2'
}

On my main Android app I have this set up. On the root project I have this classpath dependency:

classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.9'

And on the application module I apply it:

apply plugin: 'groovyx.grooid.groovy-android'

And configure as such:

androidGroovy {
  options {
    configure(groovyOptions) {
      // used so groovy can do it's magic, I think, not 100% sure
      javaAnnotationProcessing = true 
    }
  }
  skipJavaC = true // if disabled my CPU melts for some reason
}

I've also enabled Java 8 by using the Jack flag on Android:

jackOptions {
  enabled true
}

All the tests run perfect with Spock (Even the ones on the application module). However, when I try to run the app on a device or emulator I get multiple errors from Android studio. The errors happen at the task: compileDebugGroovyWithJack and it complains it can't find any of the classes from external dependencies (including support libraries):

enter image description here

Has anybody come across this problem before? It's quite a blocker :(


Solution

  • Ok, after some further investigation I found out that there where two things at play here:

    • I had skipJavaC = true in the androidGroovy extension since otherwise the compiler would take over my cpu, however
    • this was caused by having the flag org.gradle.parallel set to true.

    Once I commented out both configurations, the project compiles perfectly. Both passing check and deploying to an emulator :)