android について
androidは、ADBとシェルコマンドでAndroidデバイスを操作・調査するためのリファレンススキルです。開発者やテスター向けに、接続、アプリ管理、UI操作、ログ、システム調査、トラブルシューティングを扱います。
主な機能
- 01USBとワイヤレスでのデバイス接続
- 02アプリのインストールとパッケージ管理
- 03ファイル転送とアプリデータへのアクセス
- 04UI入力、スクリーンショット、階層ダンプ
- 05ログ、クラッシュ、システムの調査
- 06ADBのトラブルシューティング
活用シーン
- 01デバイスへのAPKのインストールと起動
- 02タップの自動化と画面キャプチャ
- 03アプリログやクラッシュレポートの調査
- 04デバイスのサービス、メモリ、設定の確認
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ hyperb1iss/ hyperdroid-skill --skill androidインストール後、Claude Code で/androidを入力して読み込まれたか確認します。
同梱ファイルreferences/deep-dive.md
詳細
Android デバイスの操作
このスキルでは、ADB とシェルコマンドを使った Android デバイスの操作についてすべて説明します。
デバイスの接続
接続済みデバイスの確認
adb devices -l
出力にはシリアル番号、ステータス、デバイス情報が表示されます。一般的なステータスは次のとおりです。
device- 接続済みで、認証されていますunauthorized- デバイスで USB デバッグの確認を承認しますoffline- 接続に問題があります。adb kill-server && adb start-serverを試してください
ワイヤレスデバッグ
Android 11 以降(推奨):
- 開発者向けオプションでワイヤレスデバッグを有効にします
- 「ペア設定コードによるデバイスのペア設定」をタップします
adb pair <ip>:<pairing_port>を実行し、コードを入力します- 続いて、
adb connect <ip>:<connection_port>を実行します
従来の方法(最初に USB 接続が必要):
adb tcpip 5555
adb connect <device_ip>:5555
複数のデバイス
デバイスを指定するには、必ず -s を使用します。
adb -s <serial> shell
adb -s emulator-5554 install app.apk
シェルコマンド
対話型シェル
adb shell # Enter shell
adb shell <command> # Run single command
adb shell "cmd1 && cmd2" # Chain commands
基本的なコマンド
# Device info
getprop ro.product.model # Device model
getprop ro.build.version.release # Android version
getprop ro.build.version.sdk # SDK level
# File operations
ls -la /sdcard/
cat /path/to/file
cp /source /dest
rm /path/to/file
# Process info
ps -A | grep <name>
pidof <package_name>
top -n 1 -m 10
出力を安全に制限する
出力が大量になる可能性があるコマンドの場合:
adb shell "logcat -d | head -500"
adb shell "dumpsys activity | head -200"
アプリの管理
インストール/アンインストール
adb install app.apk # Basic install
adb install -r app.apk # Replace existing
adb install -g app.apk # Grant all permissions
adb install -r -g app.apk # Both
adb uninstall com.example.app # Full uninstall
adb uninstall -k com.example.app # Keep data
アプリの起動/停止
# Start main activity
adb shell monkey -p com.example.app -c android.intent.category.LAUNCHER 1
# Start specific activity
adb shell am start -n com.example.app/.MainActivity
# Start with intent extras
adb shell am start -n com.example.app/.Activity \
-a android.intent.action.VIEW \
-d "myapp://page/123" \
--es "key" "value"
# Force stop
adb shell am force-stop com.example.app
# Clear app data
adb shell pm clear com.example.app
パッケージの一覧表示
adb shell pm list packages # All packages
adb shell pm list packages -3 # Third-party only
adb shell pm list packages | grep term # Filter
adb shell pm path com.example.app # APK location
adb shell dumpsys package com.example.app # Full package info
権限
adb shell pm grant com.example.app android.permission.CAMERA
adb shell pm revoke com.example.app android.permission.CAMERA
adb shell dumpsys package com.example.app | grep permission
ファイル操作
ファイルのプッシュ/プル
adb push local_file.txt /sdcard/
adb pull /sdcard/remote_file.txt ./
# Recursive
adb push local_dir/ /sdcard/target/
adb pull /sdcard/dir/ ./local/
アプリデータへのアクセス(デバッグ可能なアプリ)
adb shell run-as com.example.app ls files/
adb shell run-as com.example.app cat shared_prefs/prefs.xml
adb shell run-as com.example.app sqlite3 databases/app.db ".tables"
UI の自動化
入力コマンド
# Tap at coordinates
adb shell input tap 500 800
# Swipe (x1 y1 x2 y2 [duration_ms])
adb shell input swipe 500 1500 500 500 300
# Text input (needs focused field)
adb shell input text "hello"
# Key events
adb shell input keyevent KEYCODE_HOME # Home
adb shell input keyevent KEYCODE_BACK # Back
adb shell input keyevent KEYCODE_ENTER # Enter
adb shell input keyevent KEYCODE_POWER # Power
adb shell input keyevent KEYCODE_VOLUME_UP # Volume up
よく使うキーコード
| コード | キー | コード | キー |
|---|---|---|---|
| 3 | HOME | 4 | BACK |
| 24 | VOL_UP | 25 | VOL_DOWN |
| 26 | POWER | 66 | ENTER |
| 67 | DEL | 82 | MENU |
スクリーンショットと録画
# Screenshot
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
# One-liner (binary-safe)
adb exec-out screencap -p > screen.png
# Screen recording (max 3 min)
adb shell screenrecord /sdcard/video.mp4
adb shell screenrecord --time-limit 10 /sdcard/video.mp4
UI 階層
adb shell uiautomator dump /sdcard/ui.xml
adb pull /sdcard/ui.xml
デバッグとログ
Logcat の基本
# Dump and exit
adb logcat -d
# Last N lines
adb logcat -t 100
# Filter by tag:priority
adb logcat ActivityManager:I *:S
# Filter by package (get PID first)
adb logcat --pid=$(adb shell pidof -s com.example.app)
# Crash buffer
adb logcat -b crash
優先度レベル: V(Verbose)、D(Debug)、I(Info)、W(Warn)、E(Error)、F(Fatal)、S(Silent)
一般的なデバッグパターン
# Find crashes
adb logcat *:E | grep -E "(Exception|Error|FATAL)"
# Activity lifecycle
adb logcat ActivityManager:I ActivityTaskManager:I *:S
# Memory issues
adb logcat art:D dalvikvm:D *:S | grep -i "gc"
メモリ分析
adb shell dumpsys meminfo com.example.app
主な指標:
- PSS:比例メモリ使用量(アプリの比較に使用します)
- Private Dirty:プロセス専用のメモリ
- Heap:Java/Native ヒープの使用量
クラッシュ分析
# ANR traces
adb shell cat /data/anr/traces.txt
# Tombstones (native crashes, needs root)
adb shell ls /data/tombstones/
# Recent crashes via logcat
adb logcat -b crash -d
システムの調査
dumpsys サービス
adb shell dumpsys -l # List all services
# Common services
adb shell dumpsys activity # Activities, processes
adb shell dumpsys package <pkg> # Package details
adb shell dumpsys battery # Battery status
adb shell dumpsys meminfo # System memory
adb shell dumpsys cpuinfo # CPU usage
adb shell dumpsys window displays # Display info
adb shell dumpsys connectivity # Network state
システムプロパティ
adb shell getprop # All properties
adb shell getprop | grep <filter> # Filter properties
# Useful properties
getprop ro.product.model # Model
getprop ro.build.fingerprint # Build fingerprint
getprop ro.serialno # Serial number
getprop sys.boot_completed # Boot status (1 = done)
設定
# Namespaces: system, secure, global
adb shell settings get global airplane_mode_on
adb shell settings put system screen_brightness 128
adb shell settings list global
再起動コマンド
adb reboot # Normal reboot
adb reboot recovery # Recovery mode
adb reboot bootloader # Fastboot mode
adb reboot sideload # Sideload mode
adb reboot-bootloader # Alias for bootloader
トラブルシューティング
デバイスが見つからない場合:
adb kill-server && adb start-server
認証されていない場合:
- USB デバッグが有効になっていることを確認します
- 開発者向けオプションで USB デバッグの許可を取り消し、再接続します
複数のデバイスに関するエラー:
- デバイスを指定するには
-s <serial>を使用します
デバイス上でコマンドが見つからない場合:
- 一部のコマンドには root 権限が必要な場合や、特定のバージョンでのみ使用できる場合があります
/system/bin/<cmd>を試すか、コマンドが存在するか確認します
クイックリファレンス
| タスク | コマンド |
|---|---|
| デバイス一覧 | adb devices -l |
| アプリのインストール | adb install -r -g app.apk |
| アプリの起動 | adb shell monkey -p pkg -c android.intent.category.LAUNCHER 1 |
| アプリの停止 | adb shell am force-stop pkg |
| スクリーンショット | adb exec-out screencap -p > screen.png |
| ログ | adb logcat -d -t 100 |
| シェル | adb shell |
| ファイルのプッシュ | adb push local /sdcard/ |
| ファイルのプル | adb pull /sdcard/file ./ |
| タップ | adb shell input tap X Y |
| 戻る | adb shell input keyevent 4 |
| ホーム | adb shell input keyevent 3 |
特定のトピックを詳しく調べるには、references/deep-dive.md を参照してください。
コメント
Markdown 対応