简体   繁体   English

Android 模拟器命令行不会终止

[英]Android emulator command line will not terminate

I have a simple shell script like this (running on Mac):我有一个像这样的简单 shell 脚本(在 Mac 上运行):

/Users/abcdef/Library/Android/sdk/tools/emulator -avd Pixel_API_23
./gradlew assembleDebug assembleAndroidTest
fastlane screengrab

The problem is after running the first line, it starts an emulator just fine, but the command stalls, it will not finish so the next lines cannot be executed.问题是在运行第一行之后,它启动了一个模拟器就好了,但是命令停止了,它不会完成,因此无法执行下一行。 I tried to force-stop it, but that doesn't even work.我试图强行阻止它,但这甚至不起作用。 If I close that terminal, start a new one, and run the script again, the first command will exit (the emulator is already running) and the rest will be executed.如果我关闭该终端,启动一个新终端,然后再次运行脚本,第一个命令将退出(模拟器已在运行),其余命令将被执行。
I want to automate screenshot a series of devices, so I want to use a single shell script.我想自动截图一系列设备,所以我想使用单个shell脚本。

The emulator command finishes when the emulator exits.当模拟器退出时,模拟器命令结束。

If the emulator doesn't exit, the emulator command doesn't finish.如果模拟器未退出,则模拟器命令不会完成。

You instead want to continue without waiting for the command to finish, which you can do by running it in the background:相反,您希望继续而不等待命令完成,您可以通过在后台运行它来完成:

/Users/abcdef/Library/Android/sdk/tools/emulator -avd Pixel_API_23 &

However , the script now continues immediately, so the emulator has not finished loading by the time you run the next lines.但是,脚本现在会立即继续运行,因此在您运行下一行时,模拟器还没有完成加载。 You need to wait until the emulator is ready to accept commands.您需要等到模拟器准备好接受命令。

One simple way of doing that would be to poll using adb :一种简单的方法是使用adb进行轮询:

until adb shell true; do sleep 1; done

So all in all:所以总而言之:

/Users/abcdef/Library/Android/sdk/tools/emulator -avd Pixel_API_23 &
until adb shell true; do sleep 1; done
./gradlew assembleDebug assembleAndroidTest
fastlane screengrab

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM