xSAVIKx / AndroidScreencast

View and control your android device on PC
https://xsavikx.github.io/AndroidScreencast
Apache License 2.0
677 stars 154 forks source link

Failed to get device screenshot - Pixel 2 XL #46

Closed d1rewolf closed 6 years ago

d1rewolf commented 7 years ago

Hi there.

First off, I absolutely love this project. I really appreciate the work you've put into it.

I was using it on a Pixel XL (updated to 8.0) up until yesterday, and it was working fine. Then, however, I switched to a Pixel 2 XL, and the following happens...

If I set the screensize manually (to ), I get:

14:04:12 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 02:04:13 E/Screenshot: Unsupported protocol: 2 14:04:13 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 02:04:13 E/Screenshot: Unsupported protocol: 2 14:04:13 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 02:04:13 E/Screenshot: Unsupported protocol: 2 14:04:13 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 02:04:13 E/Screenshot: Unsupported protocol: 2 14:04:13 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 02:04:13 E/Screenshot: Unsupported protocol: 2 14:04:13 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 02:04:13 E/Screenshot: Unsupported protocol: 2 14:04:13 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 02:04:13 E/Screenshot: Unsupported protocol: 2 14:04:13 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 02:04:13 E/Screenshot: Unsupported protocol: 2 14:04:13 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 14:04:14 [AWT-EventQueue-0] INFO AndroidScreencastApplication - Stopping application 14:04:14 [Screen Capturer] WARN ScreenCaptureRunnable - IO Exception happened while getting device screenshot. Will try again in 100 ms. 14:04:14 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 14:04:14 [Screen Capturer] INFO ScreenCaptureRunnable - Stopping screen capturing 14:04:15 [Thread-1] INFO AndroidScreencastApplication - Stopping application

If I leave the screen size undefined (not set in app.properties) I get:

14:05:29 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 14:05:29 [Screen Capturer] WARN ScreenCaptureRunnable - ADB Command was rejected. Will try again in 100 ms. 14:05:29 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 14:05:29 [Screen Capturer] WARN ScreenCaptureRunnable - ADB Command was rejected. Will try again in 100 ms. 14:05:29 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 14:05:29 [Screen Capturer] WARN ScreenCaptureRunnable - ADB Command was rejected. Will try again in 100 ms. 14:05:29 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 14:05:29 [Screen Capturer] WARN ScreenCaptureRunnable - ADB Command was rejected. Will try again in 100 ms. 14:05:29 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 14:05:29 [Screen Capturer] WARN ScreenCaptureRunnable - ADB Command was rejected. Will try again in 100 ms. 14:05:29 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 14:05:29 [Screen Capturer] WARN ScreenCaptureRunnable - ADB Command was rejected. Will try again in 100 ms. 14:05:30 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 14:05:30 [Screen Capturer] WARN ScreenCaptureRunnable - ADB Command was rejected. Will try again in 100 ms.

Controls via buttons still work...it's just the screenshot capability which isn't.

Any ideas how to fix?

Thanks!

d1rewolf commented 7 years ago

Also, just an fyi...I did try adb shell screencap /sdcard/screen.png && adb pull /sdcard/screen.png, and was able to pull a screenshot successfully.

xSAVIKx commented 7 years ago

Hello.

Could you please check your ADB version? Probably there were some changes in the ADB protocol and current java library doesn't support it yet.

Also, are you using some bundle from releases or you have your own ADB?

d1rewolf commented 7 years ago

I've tried using your provided adb, and I've also tried using adb downloaded with the SDK.

I'm currently using adb 1.0.39, which is included with the latest downloads via SDK Manager (see below).

Any ideas?

Thanks in advance. ` 10:26:58 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 10:26:58 E/Screenshot: Unsupported protocol: 2 10:26:58 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 10:26:58 E/Screenshot: Unsupported protocol: 2 10:26:58 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 10:26:59 E/Screenshot: Unsupported protocol: 2 10:26:59 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 10:26:59 E/Screenshot: Unsupported protocol: 2 10:26:59 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 10:26:59 E/Screenshot: Unsupported protocol: 2 10:26:59 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 10:26:59 E/Screenshot: Unsupported protocol: 2 10:26:59 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 10:26:59 E/Screenshot: Unsupported protocol: 2 10:26:59 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 10:26:59 E/Screenshot: Unsupported protocol: 2 10:26:59 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 10:26:59 E/Screenshot: Unsupported protocol: 2 10:26:59 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot 10:26:59 E/Screenshot: Unsupported protocol: 2 10:26:59 [Screen Capturer] INFO ScreenCaptureRunnable - Failed to get device screenshot ^C10:26:59 [Thread-1] INFO AndroidScreencastApplication - Stopping application 10:26:59 [Screen Capturer] WARN ScreenCaptureRunnable - IO Exception happened while getting device screenshot. Will try again in 100 ms. 10:26:59 [Thread-1] INFO AndroidScreencastApplication - Stopping application ➜ androidscreencast-0.0.10s grep adb app.properties
adb.path=/home/username/Android/Sdk/platform-tools/adb

adb.path=./adb

adb.device.timeout=30

maximum time to execute adb command (in seconds)

adb.command.timeout=5

➜ androidscreencast-0.0.10s /home/username/Android/Sdk/platform-tools/adb version Android Debug Bridge version 1.0.39 Revision 3db08f2c6889-android Installed as /home/username/Android/Sdk/platform-tools/adb `

xSAVIKx commented 7 years ago

@jbwiv Actually right now I have no idea why it could fail :-(

I suppose something has changed with the protocol, but AFAIK ddmlib - the library that is used by the app is not yet updated (actually the last update was in march)

d1rewolf commented 7 years ago

How can you track what ddmlib makes it into production? I created my own implementation of AdbHelper's getFrameBuffer and overrode the value returned from buf.getInt() to be set to either 1 or 16 (the only protocol versions supported per RawImage.readHeader) but neither version did the trick...though I was able to get past that error I quickly hit other errors downstream.

So it appears the protocol really must have changed or the ddm jar downloaded with the project is too old. I'll explore new jars next. Thanks.

xSAVIKx commented 7 years ago

@jbwiv ddmlib should be part of the Android OSP. I've used the latest version available from the official Maven Repository, but, maybe, it could be built from sources.

xSAVIKx commented 7 years ago

@jbwiv there is kind of a hell within AOSP git repository, but even with glance look, I can see, that there were lots of changes to the ddmlib part since latest maven release. Maybe it's possible to compile from source

d1rewolf commented 7 years ago

Ok, I'll look into what it takes to do that. Thanks!

I'll let you know.

devint1 commented 6 years ago

Using ddmlib 26.0.0 bundled with the Android SDK tools worked for me.

<android-sdk>/tools/lib/ddmlib-26.0.0-dev.jar

xSAVIKx commented 6 years ago

Thanks! I'll update the implementation soon.

d1rewolf commented 6 years ago

Interesting...trying with 26.0.0 gives me:

Exception in thread "main" java.lang.NoClassDefFoundError: com/android/ddmlib/TimeoutException at com.github.xsavikx.androidscreencast.api.injector.ScreenCaptureRunnable_Factory.get(ScreenCaptureRunnable_Factory.java:27) at com.github.xsavikx.androidscreencast.api.injector.ScreenCaptureRunnable_Factory.get(ScreenCaptureRunnable_Factory.java:8) at dagger.internal.DoubleCheck.get(DoubleCheck.java:47) at com.github.xsavikx.androidscreencast.api.injector.Injector_Factory.get(Injector_Factory.java:21) at com.github.xsavikx.androidscreencast.api.injector.Injector_Factory.get(Injector_Factory.java:7) at dagger.internal.DoubleCheck.get(DoubleCheck.java:47) at com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication_Factory.get(AndroidScreencastApplication_Factory.java:59) at com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication_Factory.get(AndroidScreencastApplication_Factory.java:14) at dagger.internal.DoubleCheck.get(DoubleCheck.java:47) at com.github.xsavikx.androidscreencast.dagger.AppModule_ApplicationFactory.get(AppModule_ApplicationFactory.java:25) at com.github.xsavikx.androidscreencast.dagger.AppModule_ApplicationFactory.get(AppModule_ApplicationFactory.java:10) at dagger.internal.DoubleCheck.get(DoubleCheck.java:47) at com.github.xsavikx.androidscreencast.dagger.DaggerMainComponent.application(DaggerMainComponent.java:267) at com.github.xsavikx.androidscreencast.Main.main(Main.java:16) Caused by: java.lang.ClassNotFoundException: com.android.ddmlib.TimeoutException at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 14 more

@devint1 did you modify the source to work around this?

d1rewolf commented 6 years ago

Sorry, never mind. I had to mvn install-file the jar to get it to work. Can confirm ddmlib 26.0.0 fixes the issue. Thanks!

xSAVIKx commented 6 years ago

Yeah, but this version is not yet published into Maven Central or Bintray. And I don't really want to include my-own-compiled library.

mcmindcoder commented 6 years ago

Thank you for solution guys. I had the same issue. It's fixed now. To help others: One can download the entire 26 sdk with ddmlib-26.0.0-dev.jar included here: https://chromium.googlesource.com/android_tools/+archive/HEAD/sdk.tar.gz As for now max available version of Android SDK Tools in android repo is 25.2.5 When version 26.0.0 gets available, problem will gone naturally.

saminiir commented 6 years ago

I also made it work by updating ddmlib to 26.0.0-dev. Edited CLI history:

$ java -version
openjdk version "1.8.0_144"
OpenJDK Runtime Environment (build 1.8.0_144-b01)
OpenJDK 64-Bit Server VM (build 25.144-b01, mixed mode)
$ curl -L https://chromium.googlesource.com/android_tools/+archive/HEAD/sdk.tar.gz | tar -xvzf - tools/lib/ddmlib-26.0.0-dev.jar
$ git diff -U1 pom.xml
diff --git a/pom.xml b/pom.xml
index 669f439..b76a7ea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,3 +10,3 @@
         <dagger2.version>2.10</dagger2.version>
-        <ddmlib.version>25.3.0</ddmlib.version>
+        <ddmlib.version>26.0.0-dev</ddmlib.version>
         <slf4j.version>1.7.25</slf4j.version>
$ bash mvnw install:install-file -Dfile=tools/lib/ddmlib-26.0.0-dev.jar -Dversion=26.0.0-dev -DgroupId=com.android.tools.ddms -DartifactId=ddmlib -Dpackaging=jar
$ bash mvnw install
$ java -jar target/androidscreencast-0.0.11s-SNAPSHOT-executable.jar
sagarsheth27 commented 6 years ago

@mc-android-developer, I am downloaded it. Now how to use it. What steps I have to follow? Could you please guide me.

StayZeal commented 6 years ago

Linux: download :https://chromium.googlesource.com/android_tools/+archive/HEAD/sdk.tar.gz overide:tool/lib

Android 6.0 does not work .........

artig commented 6 years ago

Unable to take screenshot Nexus5X Android 8.1

I tried with ddmlib 26.0.0 but it is not working for me. Also, I have overridden the tool/lib with the above. Still it is not working.

Getting the below error on the terminal: E/Screenshot: Unsupported protocol: 2

And on UiAutomatorViewer getting the below error: Unexpected error while obtaining UI hierarchy java.lang.reflect.InvocationTargetException

Any ideas how to fix? Thank you in advance

xSAVIKx commented 6 years ago

@artig what version of the app do you use?

xSAVIKx commented 6 years ago

@StayZeal what version of the app do you use? Have you tried the latest one with the updated ddmlib version inside?

Mayuresh92 commented 4 years ago

Unable to take screenshot Nexus5X Android 8.1

I tried with ddmlib 26.0.0 but it is not working for me. Also, I have overridden the tool/lib with the above. Still it is not working.

Getting the below error on the terminal: E/Screenshot: Unsupported protocol: 2

And on UiAutomatorViewer getting the below error: Unexpected error while obtaining UI hierarchy java.lang.reflect.InvocationTargetException

Any ideas how to fix? Thank you in advance

Hi,

I was facing same problem on my real device, but now I have resolved my problem. When I was facing this problem, at that time I was using Android SDK Tools with version 25.0.0 and SDK platform with version Android 10.0(Q). So I have updated my SDK Tools version to 26.1.1 and also I got switched to SDK Platform Android 8.1(Oreo). These steps solved my problem now I am able to take screenshot on uiautomatorviewer. I have updated SDK Tools and SDK platform using Android studio. Please check if these steps can help you to solve your problem.

xSAVIKx commented 4 years ago

Hi @Mayuresh92. Thanks for your comment. Have you tried the latest versions of the app? I believe we're already using newer versions of both ddmlib and platform tools

Mayuresh92 commented 4 years ago

Hi @Mayuresh92. Thanks for your comment. Have you tried the latest versions of the app? I believe we're already using newer versions of both ddmlib and platform tools

Hi,

I have been using Platform-Tools with version 29.0.0 My android version is 10 and using ddmlib-26.0.0-dev