摇篮的Andr​​oid依赖于构建工具0.11“AAR”单元测试。+ [英] Gradle Android unit tests that depend on an 'aar' for build tool 0.11.+

查看:196
本文介绍了摇篮的Andr​​oid依赖于构建工具0.11“AAR”单元测试。+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gradle这个构建系统运行Roboletric测试然而我遇到了在这里<一个描述的问题href=\"http://stackoverflow.com/questions/21099754/gradle-android-unit-tests-that-depend-on-an-aar\">Gradle依赖于一个AAR但解决的办法只适用于构建工具0.9版Android的单元测试。+,而不是0.11。+
因为我无法找到爆炸-AAR目录。任何想法?

下面是部分构建文件

 配置{
    testLocalCompile {
        extendsFrom编译
    }
}sourceSets {
    testLocal {
        java.srcDir文件('的src / test / java下)
        resources.srcDir文件('的src /测试/ RES')
        compileClasspath + = configurations.testLocalCompile
        runtimeClasspath + = compileClasspath
    }
}依赖{
testLocalCompile文件树(导演:$ project.buildDir /中间体/爆炸-AAR,包括:** / classes.jar)}任务localTest(类型:测试,dependsOn:组装){
    testClassesDir = sourceSets.testLocal.output.classesDir    android.sourceSets.main.java.srcDirs.each {DIR - &GT;
        高清buildDir = dir.getAbsolutePath()。斯普利特('/')
        buildDir =(buildDir [0 ..(buildDir.length - 4)] + ['建设','中间','班','调试'])。加入('/')        sourceSets.testLocal.compileClasspath + =文件(buildDir)
        sourceSets.testLocal.runtimeClasspath + =文件(buildDir)
    }    CLASSPATH = sourceSets.testLocal.runtimeClasspath
}check.dependsOn localTest


解决方案

固定它。它似乎是在0.11 +构建工具的爆炸-AAR文件夹移动到根。我不得不改变依赖:

  testLocalCompile文件树(导演:$ {} ROOTDIR /建设/爆炸-AAR,包括:** / classes.jar)

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

解决方案

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

这篇关于摇篮的Andr​​oid依赖于构建工具0.11“AAR”单元测试。+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆