是否可以“强行停止”?我正在终端中使用 adb 调试应用程序?
我正在开发一个应用程序,为了调试首次安装时的某些操作,我发现使用终端命令:
./adb uninstall <package-name>
比导航到设置、应用程序、等待应用程序加载、查找应用程序并卸载它要快得多。我强烈推荐给尚未使用它进行调试的任何人。
现在我正在尝试处理我的应用程序的强制关闭部分,但我在 android 文档中找不到有关如何通过 adb 命令强制关闭应用程序的说明。
是否可以?
I am developing an app, and for debugging certain actions on first installation I found that using the terminal command:
./adb uninstall <package-name>
was a lot fast than navigating to settings, apps, waiting for the apps to load, finding your app, and uninstalling it. I would strongly recommend it for anyone that doesn't already use it for debugging.
Now I am trying to work on the force close part of my app, and I can't find anywhere in the android doc, instructions on how to force close an app by adb command.
Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用
adb shell kill
来终止进程,但首先您需要找到进程ID。为此,您可以使用adb shell ps
并解析输出。这是一个示例(假设您的开发 PC 是 Unix):You can use
adb shell kill
to kill the process, but first you need to find the process id. To do this you can useadb shell ps
and parse the output. Here is a sample (assuming your development PC is Unix):您可以使用他的 pid 来关闭它,
但我不确定是否使用包名称来执行此操作。
You can close one by his pid using
but I'm not sure of doing it with a package name.
我创建了一个批处理脚本来运行此命令。
I've created a batch script to run this command.
如果由于某种原因无法使用 awk(在我的例子中,cygwin 安装不完整),以下方法可能有效:
adb shell ps | grep 您的.PACKAGE.NAME | sed 's/\s\s*/ /g' | sed 's/\s\s*/ /g' |切 -d ' ' -f 2 | adb shell kill
说明:首先,
ps
列出正在运行的进程。从输出中,grep
获取包含 YOUR.PACKAGE.NAME 的行。sed
将连续的空格截断为一个,以帮助cut
获取该行的包名称部分。最后,进程 ID 通过管道传送到kill
。If you can't use
awk
for some reason (incomplete cygwin installation in my case), the following might work:adb shell ps | grep YOUR.PACKAGE.NAME | sed 's/\s\s*/ /g' | cut -d ' ' -f 2 | adb shell kill
Explanation: First,
ps
lists running processes. From the output,grep
gets the line containing YOUR.PACKAGE.NAME.sed
truncates consecutive spaces into one to helpcut
can get the package name part of that line. Finally, the process id is piped tokill
.这个命令对我有用。希望这也会对您有所帮助。
This command worked for me. Hope so this will help you as well.