【问题标题】:Gradle Android unit tests that depend on an 'aar' for build tool 0.11.+Gradle Android 单元测试依赖于构建工具 0.11.+ 的“aar”
【发布时间】:2014-06-19 20:18:40
【问题描述】:

我正在使用 gradle 构建系统来运行 Roboletric 测试,但是我遇到了这里描述的问题 Gradle Android unit tests that depend on an 'aar' 但该解决方案仅适用于构建工具版本 0.9.+ 而不是 0.11.+ 因为我找不到exploded-aar 目录。有什么想法吗?

这是部分构建文件

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

【问题讨论】:

  • 你能分享你的 build.gradle 文件吗?另外,您是在 AS 中还是从控制台运行测试?
  • 我是从控制台运行的,但是没有看到exploded-aar目录
  • 应该注意的是,从第一篇关于 SO (stackoverflow.com/a/16952507/821636) 上的“localTest”单元测试hack 的帖子中,请注意在 buildDir 创建中添加了“中间体”。

标签: android unit-testing gradle robolectric


【解决方案1】:

0.12.2

再次发生这种变化

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

将解压缩的 aar 移回每个项目中,作为可能的竞争条件的临时修复。

所以你必须把依赖改回来:

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

(PS:不知道在stackoverflow中发布这个是否正确)

【讨论】:

    【解决方案2】:

    已修复:似乎在 0.11.+ 构建工具中,exploded-aar 文件夹已移至根目录。我不得不改变依赖:

    testLocalCompile fileTree(dir: "${rootDir}/build/exploded-aar", include: "**/classes.jar")
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    • 2014-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多