简体   繁体   English

Linux上的Android screenshot2工具NullPointerException

[英]Android screenshot2 Tool NullPointerException on Linux

I am using: 我在用:

Java Version: 7 Java版本:7

SDK Tools, Revision 24.4.1 (October 2015) SDK工具,修订版24。4。1(2015年10月)

Taking a screenshot with the tool screenshot2 raise a NullPointerException on Ubuntu Server 14.04 and Kali Linux 2.0. 使用工具screenshot2截取屏幕截图会在Ubuntu Server 14.04和Kali Linux 2.0上引发NullPointerException。 It works on Mac OS X 10.11. 它适用于Mac OS X 10.11。

Command: 命令:

$ screenshot2 -e image.png

(Error happens even with the -s argument or without) (即使使用-s参数也不会发生错误)

Error: 错误:

Exception in thread "main" java.lang.NullPointerException
at com.android.ddmlib.MonitorThread.wakeup(MonitorThread.java:580)
at com.android.ddmlib.MonitorThread.quit(MonitorThread.java:588)
at com.android.ddmlib.AndroidDebugBridge.terminate(AndroidDebugBridge.java:235)
at com.android.screenshot.Screenshot.main(Screenshot.java:198)

Is there a fix or does anyone know the reason for this? 是否有修复或有人知道这个的原因?

I found a solution that avoid using the screenshot2 tool. 我找到了一个避免使用screenshot2工具的解决方案。

Dependencies for Linux: Linux的依赖关系:

sudo apt-get install zlib1g-dev libjpeg-dev

Maybe it works even without on your machine but I don't thing so. 也许它甚至可以在你的机器上工作,但我不是这样。

Then you need the python package pillow version 2.9.0 然后你需要python包枕头版本2.9.0

Dependency for Mac AND Linux: Mac和Linux的依赖关系:

sudo pip install pillow==2.9.0

I made this really basic script that create the screenshot image. 我制作了这个非常基本的脚本来创建截图图像。

File screenshot.py 文件screenshot.py

from StringIO import StringIO
from PIL import Image
import sys

binary = sys.stdin.read().replace('\r\n', '\n')
stream = StringIO(binary)
image = Image.open(stream)
image.save(sys.argv[1], 'PNG')

Now you can use the command line to simply get a screenshot from the device like I tried above. 现在,您可以使用命令行简单地从设备上获取屏幕截图,就像我上面尝试过的那样。

Example: 例:

adb shell screencap -p | python screenshot.py image.png

Or with the -s argument for a specific device 或者使用特定设备的-s参数

adb shell -s emulator-5558 screencap -p | python screenshot.py image.png

For those who don't want to mess with python for a simple screenshot, here is a bash one-liner, without any extra dependencies: 对于那些不想使用python进行简单截屏的人来说,这里有一个bash单线程,没有任何额外的依赖:

adb exec-out screencap -p >YOUR_FILE.png

You can also make it a bash script for daily use. 您还可以将其设为日常使用的bash脚本。

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

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