【发布时间】:2017-06-17 04:25:05
【问题描述】:
我正在编写一个 gradle 任务,以便在运行 espresso 测试之前将 apk 安装到模拟器。
这是我目前的任务。
task installButlerApk {
doLast {
println "Verifying test-butler installation in emulators"
final adb = "$android.sdkDirectory.absolutePath/platform-tools/adb"
final String[] split = ["$adb", "devices", "-l"].execute().text.split("\\r?\\n")
split.each {
if (it.isEmpty())
return;
println "Emulator: $it"
final emu = it.split("\\s")[0]
checks whether the APK is already installed
if (["$adb", "-s", "$emu", "shell", "pm", "list", "packages"].execute().text.contains(butlerPackage))
return;
final installResult = ["$adb", "-s", "$emu", "install", "$butlerApkPath"].execute().text
if (!installResult.contains("Success"))
println "Could not install APK. Install output:\n$installResult"
else
println "Installed $butlerApkPath in $emu successfully"
}
}
}
但是,当我通过终端运行它时,任务最终会冻结。我不确定为什么。我对此进行了一些研究,有一次我认为传递给 ProcessGroovyMethods 执行的命令失败了,因为它是作为字符串传递的(execute(String self)),所以我使用了执行的数组表示(execute(String[] commandArray) ) 看看这是否可行,但我仍然得到相同的结果,所以我只是要求有编写这些任务经验的人给我一些帮助。到目前为止,我正在打印命令的结果,它没有显示任何错误。它只是在构建过程中停留了几个小时。
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Joel\Documents\Projects\Forms>gradlew installButlerApk
Picked up _JAVA_OPTIONS: -XX:ParallelGCThreads=2
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon:
https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html.
Incremental java compilation is an incubating feature.
:app:installButlerApk
Verifying test-butler installation in emulators
Emulator: List of devices attached
> Building 0% > :app:installButlerApk
【问题讨论】:
标签: android gradle groovy android-emulator adb