我想设置.apk文件,用于使用SpoonGradlePlugin运行我的测试。
我可以通过gradle文件以编程方式设置可用的属性:
但我的项目有各种风格和名称,我想测试它们。通过当前设置,我得到:
* What went wrong:
A problem was found with the configuration of task ':app:spoonDebugAndroidTest'.
> File '/Users/F1sherKK/Dev/MyApp-Android/app/build/outputs/apk/app-debug.apk' specified for property 'applicationApk' does not exist.
我的构建名称是:
app-debug-androidTest-unaligned.apk
MyApp-debugA-1.2.3-201.apk
MyApp-debugB-1.2.3-201.apk
MyApp-debugC-1.2.3-201.apk
这就是为什么我想在gradle代码中设置我的.apk - 或者控制台。到目前为止我发现Spoon Gradle插件中有可用的字段:
名称:
/** Instrumentation APK. */
@InputFile
File instrumentationApk
/** Application APK. */
@InputFile
File applicationApk
但我无法在SpoonExtension.groovy中访问gradle中的属性。
有没有办法设置这些字段?
//编辑 - 添加了一些尝试: 这是我的基础配置:
spoon {
debug = true
baseOutputDir = file("$buildDir/spoon-log")
if (project.hasProperty('spoonClassName')) {
className = project.spoonClassName
if (project.hasProperty('spoonMethodName')) {
methodName = project.spoonMethodName
}
}
}
任务扩展它并覆盖instumentationArgs来设置包并启动其他类型的测试。
task spoonAllTests(type: GradleBuild, dependsOn: ['spoon']) {
spoon {
instrumentationArgs = ["package=com.myapp.sendmoney.instrumentation"]
}
}
task spoonFlowTests(type: GradleBuild, dependsOn: ['spoon']) {
spoon {
instrumentationArgs = ["package=com.myapp.instrumentation.flowtests"]
}
}
现在我尝试编辑applicationApk或instrumentationApk文件:
Edit2:我尝试了新事物:
task spoonFlowTests(type: GradleBuild, dependsOn: ['spoon']) {
spoon {
inputs.property("applicationApk", "$buildDir/outputs/apk/ap12345p-debug.apk")
inputs.property("instrumentationApk", "$buildDir/outputs/apk/ap125p-debug.apk")
println inputs.getFiles()
println inputs.getProperties()
instrumentationArgs = ["package=com.azimo.sendmoney.instrumentation.flowtests"]
}
}
终端回复:
2015-10-26 20:24:12 [SR.runTests] Executing instrumentation suite on 0 device(s).
2015-10-26 20:24:12 [SR.runTests] Application: com.azimo.sendmoney.debug1 from /Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/app-debug.apk
2015-10-26 20:24:12 [SR.runTests] Instrumentation: com.azimo.sendmoney.debug1.test from /Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/app-debug-androidTest-unaligned.apk
:app:spoon
:app:spoonFlowTests
file collection
{instrumentationApk=/Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/ap125p-debug.apk, applicationApk=/Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/ap12345p-debug.apk}
:Azimo-Android:app:help
Welcome to Gradle 2.5.
To run a build, run gradlew <task> ...
To see a list of available tasks, run gradlew tasks
To see a list of command-line options, run gradlew --help
To see more detail about a task, run gradlew help --task <task>
BUILD SUCCESSFUL
Total time: 13.289 secs
答案 0 :(得分:4)
您可以在更改apk名称后应用Spoon插件,如下所示:
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace(".apk", "-${variant.versionName}.apk"))
}
}
afterEvaluate {
apply plugin: 'spoon'
spoon {
debug = true;
}
}
答案 1 :(得分:0)
我们需要考虑参数的注释:
/** Instrumentation APK. */
@InputFile
File instrumentationApk
/** Application APK. */
@InputFile
File applicationApk
由于它们被标记为@InputFile
,我们应该能够创建一个自定义任务,该任务取决于使用 input.files 属性<传递输入的Spoon / strong>即可。
一个粗略的例子(未经测试):
task customSpoon(type: Exec, dependsOn: spoon) {
inputs.files ["path/instrumentation.apk", "path/debuggable.apk"]
}
作为替代方案,只需创建一个自定义任务,模拟对基本Spoon任务的命令行参数化调用,如下所示
task runSpoonTask(type: Exec) {
commandLine './gradlew', 'spoon', '$buildDir/outputs/apk/ap12345p-debug.apk', '$buildDir/outputs/apk/ap125p-debug.apk'
}
答案 2 :(得分:0)
请参阅my answer to your different question,说明配置任务的方式有误。
答案 3 :(得分:0)
我遇到了同样的问题:
...指定属性&#39; applicationApk&#39;不存在
我们用它来重命名&#34; app-debug.apk&#34; to&#34; currentProject-debug.apk&#34;:
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace("app", "${project.hdmiAppName}"))
}
}
但似乎Spoon的效果更好:
defaultConfig {
applicationId packageName
...
setProperty("archivesBaseName", "${project.hdmiAppName}")
}
这会将APK-Name的&#34; app&#34; -Part重命名为您喜欢的任何内容。在我们的例子中,我们在属性文件中指定了"${project.hdmiAppName}"
。但我想它也可以是"MyApp-${versionName}"
。