问题描述
希望能够依靠的AAR在一个摇篮,Android项目我的单元测试。我不想手动包括我的项目内外部库的源文件或二进制文件(有多种原因)。
我们可以依靠远程AAR文件,这样在build.gradle:
编译com.facebook:Facebook的Android的SDK:3.6.0:@aar
但是,使用此处描述的摇篮测试方法时: http://stackoverflow.com/a/16952507/821636 (由于杰克沃顿商学院的的插件,是还没有应用),试图包括一个AAR的一个依赖关系的方法是这样的:
testLocalCompilecom.facebook:Facebook的Android的SDK:3.6.0:@aar
好像没有真正包括AAR的类路径中测试(与运行./ gradlew检查
),因为我得到的NoClassDefFoundError
上课的AAR。注意:当JAR依赖被列入这样一来,他们的工作
思维一定有什么东西在 localTest
的任务,需要添加AAR的扩展,因为它不依赖(罐)的默认类型。
下面是该任务将这样,请回答上面提到的复制副本:
任务localTest(类型:测试,dependsOn:assembleDebug){
testClassesDir = sourceSets.testLocal.output.classesDir
workingDir =$ {rootProject.projectDir} / APP / src目录/主
android.sourceSets.main.java.srcDirs.each {DIR - >
高清buildDir = dir.getAbsolutePath()。斯普利特('/')
buildDir =(buildDir [0 ..(buildDir.length - 4)] + ['打造','班','调试'])。加入(/)
sourceSets.testLocal.compileClasspath + =文件(buildDir)
sourceSets.testLocal.runtimeClasspath + =文件(buildDir)
}
CLASSPATH = sourceSets.testLocal.runtimeClasspath
}
我遇到了这个问题,并找到了解决方案 - 包括来自在build文件夹中的爆炸包(.aar)的classes.jar。我不认为将有助于虽然发现在.aar依赖的资源。
testLocalCompile文件树(导演:$ project.buildDir /爆炸-包,包括:** / classes.jar)
编辑:由于Android的摇篮构建工具 0.9.0 的依赖已更改为:
androidTestCompile文件树(导演:$ project.buildDir /爆炸-AAR,包括:** / classes.jar)
由于Android的摇篮插件
0.12.2提供
testLocalCompile文件树(导演:$ project.buildDir /中间体/爆炸-AAR /,包括:** / classes.jar)
Want to be able to depend on an AAR for my unit tests in a Gradle-Android project. I do not want to manually include the external library source or binaries inside my project (for multiple reasons).
We can depend on remote aar files like this in the build.gradle:
compile 'com.facebook:facebook-android-sdk:3.6.0:@aar'
But when using the gradle test method described here: http://stackoverflow.com/a/16952507/821636 (Since Jake Wharton's plugin, isn't quite there yet), trying to include an aar as a dependency for that method like this:
testLocalCompile 'com.facebook:facebook-android-sdk:3.6.0:@aar
Does not seem to actually include the aar in the classpath for tests (run with ./gradlew check
) since I get NoClassDefFoundError
for classes in the aar. NOTE: When jar dependencies are included this way, they work.
Thinking there must be something in that localTest
task that needs to add the aar extension since it's not the default type of dependency (jar).
Here is copy of that task copied from the SO answer referenced above:
task localTest(type: Test, dependsOn: assembleDebug) {
testClassesDir = sourceSets.testLocal.output.classesDir
workingDir = "${rootProject.projectDir}/app/src/main"
android.sourceSets.main.java.srcDirs.each { dir ->
def buildDir = dir.getAbsolutePath().split('/')
buildDir = (buildDir[0..(buildDir.length - 4)] + ['build', 'classes', 'debug']).join('/')
sourceSets.testLocal.compileClasspath += files(buildDir)
sourceSets.testLocal.runtimeClasspath += files(buildDir)
}
classpath = sourceSets.testLocal.runtimeClasspath
}
I ran into this problem and found a solution - include the classes.jar from the exploded bundle (.aar) in the build folder. I don't think will help with finding resources in .aar dependencies though.
testLocalCompile fileTree(dir: "$project.buildDir/exploded-bundles", include: "**/classes.jar")
Edit: Since Android Gradle build tools 0.9.0 the dependency has changed to:
androidTestCompile fileTree(dir: "$project.buildDir/exploded-aar", include: "**/classes.jar")
As of Android Gradle plugin 0.12.2:
testLocalCompile fileTree(dir: "$project.buildDir/intermediates/exploded-aar/", include:"**/classes.jar")
这篇关于依赖于一个“AAR”摇篮Android的单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!