2

I am using gradle build system to run Roboletric tests however I've encountered the problem that was described here Gradle Android unit tests that depend on an 'aar' but the solution only works for build tool version 0.9.+ and not 0.11.+ as I cannot find the exploded-aar directory. Any ideas?

Here's the partial build file

configurations {
    testLocalCompile {
        extendsFrom compile
    }
}

sourceSets {
    testLocal {
        java.srcDir file('src/test/java')
        resources.srcDir file('src/test/res')
        compileClasspath += configurations.testLocalCompile
        runtimeClasspath += compileClasspath
    }
}

dependencies {
testLocalCompile fileTree(dir: "$project.buildDir/intermediates/exploded-aar", include: "**/classes.jar")

}

task localTest(type: Test, dependsOn: assemble) {
    testClassesDir = sourceSets.testLocal.output.classesDir

    android.sourceSets.main.java.srcDirs.each { dir ->
        def buildDir = dir.getAbsolutePath().split('/')
        buildDir =  (buildDir[0..(buildDir.length - 4)] + ['build', 'intermediates', 'classes', 'debug']).join('/')

        sourceSets.testLocal.compileClasspath += files(buildDir)
        sourceSets.testLocal.runtimeClasspath += files(buildDir)
    }

    classpath = sourceSets.testLocal.runtimeClasspath
}

check.dependsOn localTest
Community
  • 1
  • 1
user3709877
  • 161
  • 11
  • Can you share your build.gradle file? Also are you running test in AS or from console? – Eugen Martynov Jun 19 '14 at 21:01
  • I'm running from the console, but I do not see the exploded-aar directory – user3709877 Jun 19 '14 at 21:49
  • It should be noted that from the first post about the "localTest" unit test hack on SO (http://stackoverflow.com/a/16952507/821636), notice the addition of "intermediates" in the buildDir creation. – Colin M. Aug 25 '14 at 20:31

2 Answers2

4

That change again in 0.12.2

http://tools.android.com/tech-docs/new-build-system

Move unzipped aar back in each project as a temporary fix for a possible race condition.

So you have to change the dependency back:

unitTestCompile fileTree(dir: "$project.buildDir/intermediates/exploded-aar/", include:"**/classes.jar")

(PS: do not know if is it the right way to post this in stackoverflow)

sagix
  • 600
  • 1
  • 4
  • 15
1

Fixed it: it seems like in the 0.11.+ build tool the exploded-aar folder is moved to root. I had to change the dependency:

testLocalCompile fileTree(dir: "${rootDir}/build/exploded-aar", include: "**/classes.jar")
user3709877
  • 161
  • 11
  • I don't understand why are you playing with folders. Here is mine gradle file (https://github.com/emartynov/UrlSetter/blob/master/build.gradle) – Eugen Martynov Jun 20 '14 at 07:12