CLOVER🍀

That was when it all began.

Ubuntu Linux 20.04 LTSに、Androidの画面をPCに転送するscrcpyをインストールする

これは、なにをしたくて書いたもの?

自分はAndroidユーザーなのですが、PCに画面を転送する方法はないのかな?と思って調べたらscrcpyというものを
使えばできそうだったので、試してみました。

scrcpy

scrcpyのGitHubリポジトリは、こちら。

GitHub - Genymobile/scrcpy: Display and control your Android device

scrcpyは、USB接続されたAndroidバイスの表示と制御を行うソフトウェアです。

Androidバイス側にroot権限は必要ありません。動作環境は、LinuxWindowsmacOSです。

環境

今回の環境は、こちらです。Ubuntu Linux 20.04 LTS。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:    20.04
Codename:   focal


$ uname -srvmpio
Linux 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Android端末側の準備

Android側の要求事項、準備はこちらです。

Requirements

Android 5.0以上であること。

あとは以下のドキュメントに沿って、開発者向けオプションを表示できるようにしてUSBデバッグが有効になっていること。

Android Debug Bridge (adb)  |  Android Developers

ここまでが要求事項、準備です。

scrcpyをインストールする

scrcpyのインストール方法はこちら。

Get the app

Ubuntu Linuxの場合は、aptでインストールできます。

$ sudo apt install scrcpy

snapのパッケージとして入れることもできます。

今回インストールしたscrcpyのバージョンは、こちら。

$ scrcpy --version
scrcpy 1.12.1

dependencies:
 - SDL 2.0.10
 - libavcodec 58.54.100
 - libavformat 58.29.100
 - libavutil 56.31.100

あとはAndroid端末をUSB接続して、scrcpyを起動します。

$ scrcpy

これで、PC側にAndroidの画面が転送されてきます。マウス、キーボードでの操作も可能です。

ヘルプやmanも見れるので、オプション等を指定したければこちらへ…。

$ scrcpy --help


$ man scrcpy

トラブルシュート

接続対象のAndroid端末のUSBデバッグが有効になっていないと、こうなります。

$ scrcpy
INFO: scrcpy 1.12.1 <https://github.com/Genymobile/scrcpy>
* daemon not running; starting now at tcp:5037
* daemon started successfully
adb: error: failed to get feature set: no devices/emulators found
ERROR: "adb push" returned with value 1

接続したPCからのUSBデバッグ許可をしていないと、こうなります。

$ scrcpy
INFO: scrcpy 1.12.1 <https://github.com/Genymobile/scrcpy>
adb: error: failed to get feature set: device unauthorized.
This adb server's $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.
ERROR: "adb push" returned with value 1