我有一个Gradle任务,用于启动安装在已连接的Android设备上的应用。该应用程序旨在执行一些操作,然后关闭自己,我的任务应该检测到这一点。该应用程序是一个Unity构建的应用程序,它的价值 - 虽然我不确定它应该重要。
当然,我对Gradle相当新,所以请原谅这里发生的任何愚蠢错误。
任务如下:
task androidTests(type: Exec) {
def output = new ByteArrayOutputStream()
println "Starting Unity Sample App"
commandLine 'adb', 'shell', 'am', 'start', '-n', "com.foo.bar/com.unity3d.UnityPlayerActivity"
while(!output.toString().contains('com.foo.bar')) {
// Wait for the app to launch
println "Sample app is not running yet."
commandLine "adb", "shell", "ps", "yPlayerActivity"
}
// Now wait for the app to close
while(output.toString().contains(packageName)) {
println "Sample app has not closed yet."
commandLine "adb", "shell", "ps", "yPlayerActivity"
}
}
目前,此任务除了垃圾邮件我的控制台之外什么也没做。示例应用程序尚未运行。",并且该应用程序无法在设备上启动。奇怪的是,如果我删除第一个while
循环,则任务完成,应用程序将在我的设备上启动。
有谁知道这里可能有什么问题?似乎第一个while循环实际上阻塞了之前的commandLine语句,不知何故。任何帮助解决这个问题将不胜感激。谢谢!