見出し画像

MacからAndroidの画面を共有できるようにscrcpyを入れてみた

Androidを事前にアプリを入れずにMacに画面が共有できないか考えていたらscrcpyというのを見つけました。仕組みはCyberAgent開発者ブログが紹介しています。

環境

macOS Catalina10.15.7
端末 Pixel 3a / Android 11

何代目か移行したり試行錯誤セットアップしたりして開発環境は積み重ねでぐちゃぐちゃになっています。

インストール、とか

サイトはここ https://github.com/Genymobile/scrcpy

 brew install scrcpyをしたら早速エラーが。

Error: python@3.9: the bottle needs the Apple Command Line Tools to be installed.
  You can install them, if desired, with:
    xcode-select --install

You can try to install from source with:
  brew install --build-from-source python@3.9

xcodeが古すぎるのかもしれない。表示されているコマンドを素直に実施

% xcode-select --install
xcode-select: note: install requested for command line developer tools

インストールウィンドウが立ち上がって完了
続いて pythonをインストール

% brew install --build-from-source python@3.9

これも特に止まることなく完了して再度インストールbrew install scrcpyを実施したらまたエラー。

At runtime, adb must be accessible from your PATH.
You can install adb from Homebrew Cask:
brew install --cask android-platform-tools

そういえば一通りandroid sdkをアンインストールしたんだった。公式のところにも書いてありました。

You need adb, accessible from your PATH. If you don't have it yet:

https://github.com/Genymobile/scrcpy#macos

エラーメッセージのアドバイスに従ってインストールし完了。

% brew install --cask android-platform-tools
android-platform-tools was successfully installed!

3度目の正直ということで brew install scrcpyをインストール完了

早速USBをつないで実行してみるとエラー。

% scrcpy                    
scrcpy 1.21 <https://github.com/Genymobile/scrcpy>
error: no devices/emulators found
2022-01-05 22:28:52.314 scrcpy[89787:2141877] ERROR: "adb get-serialno" returned with value 1
2022-01-05 22:28:52.314 scrcpy[89787:2141877] ERROR: Could not get device serial
2022-01-05 22:28:52.475 scrcpy[89787:2141821] ERROR: Server connection failed

Androidをつないだはいいけど開発者モードにするのを忘れていました。
開発者モードにして再度実行すると成功です

% scrcpy
scrcpy 1.21 <https://github.com/Genymobile/scrcpy>
/usr/local/Cellar/scrcpy/1.21/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 46.4 MB/s (40067 bytes in 0.001s)
[server] INFO: Device: Google Pixel 3a (Android 11)
2022-01-05 22:29:13.387 scrcpy[89789:2142008] INFO: Renderer: metal
2022-01-05 22:29:13.396 scrcpy[89789:2142008] INFO: Initial texture: 1080x2216
2022-01-05 22:29:26.453 scrcpy[89789:2142008] INFO: New texture: 2216x1080
2022-01-05 22:29:44.693 scrcpy[89789:2142008] INFO: New texture: 1080x2216
2022-01-05 22:30:26.909 scrcpy[89789:2142008] INFO: New texture: 2216x1080
2022-01-05 22:32:25.003 scrcpy[89789:2142008] INFO: New texture: 1080x2216

アプリを起動すると横画面になったり縦画面になったりするのでそのたびにログが出力されている模様です。

問題なく画面が共有されました。マウスで画面も操作できます。試しにいくつかアプリを起動して操作できました。FGOなどは開発者モードではアプリ起動がうまくできないこともあると思うので注意が必要です。

オンライン飲み会とかでちょこっとゲーム画面を見せたい時とかに使えそうな予感。本当はゲームをMacから操作したいところ。


よろしければサポートお願いします。プロデュース代になります