1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Android】リモート環境上からローカルPCに接続した端末に対してADBコマンドを実行する方法

Last updated at Posted at 2025-05-07

キーワード

  • Android
  • AndroidStudio
  • ADB

やりたいこと:thinking:

  • Androidの開発環境がリモート環境上にある場合、ローカルPCに接続したAndroid端末に対してADBコマンドを実行したい
  • 開発途中のアプリをインストールしたAndroid端末のプロセスにアタッチしてデバックしたい

方法

  1. ローカル環境上でADB serverを起動する
  2. ADB通信(port: 5037)をリモート環境からローカル環境に向けてポート転送させる

実際にやってみた

検証環境

  • ローカルPC
    • windows11
  • Android端末
    • Android 13
  • リモートPC
    • windows11(virutal box上に準備)
    • ※ローカルPCと同一のブロードキャストドメインになるようにNWの設定はブリッジアダプターを指定

1. adbのインストール

2. ローカルPCでadb serverを起動

  • 以下のコマンドを実行
  • ADBサーバが5037番ポートで起動したのを確認する
C:\Users\local\platform-tools-latest-windows\platform-tools> ./adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully

3. SSHでポート転送を設定

  • リモートPCのipアドレスを確認する
  • リモートPC上の5037番ポートへの問い合わせを、ローカルPC上の5037番ポートに転送するように設定する
C:\Users\local\platform-tools-latest-windows\platform-tools> ssh -R 5037:localhost:5037 test@192.168.3.4 -v

4. リモートPC上でADBコマンドを実行

  • adb logcatなど実行すると端末のログが確認できます
C:\Users\remote\platform-tools-latest-windows\platform-tools> ./adb devices
List of devices attached
SXILHMA261700953        device

まとめ

  • リモートPC上からローカルPCに接続した端末に対してADBコマンドを実行するには、5037番ポートをローカルに転送させれば良い
  • 言い換えるとADB通信をSSHトンネルさせれば良い

追記

  • 関連記事
    • @hamupさんの以下の記事でもNW越しにADBコマンドを実行する方法が議論されています
      • adb connectコマンドで同一NW上のAndroid内のadbデーモンに接続する方法です
      • ネットワーク経由でadb実行する
      • Androidスマホがadbコマンドを実行したいホストと同一NW上にない場合は本記事で議論したようにadb serverに対してポート転送するしかないと理解しています
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?