LoginSignup
73
74

More than 5 years have passed since last update.

きっと開発が楽しくなるADBコマンドまとめ

Last updated at Posted at 2015-12-09

はじめに

adb系のコマンドはいろんなことができるので
よく使うものをメインにまとめておきます

コマンド一覧

接続されたAndroid端末が認識されているか確認する

adb devices

※複数接続されている場合、この実行結果にあるシリアルコードを利用して端末指定が可能

result
c:\>adb devices
List of devices attached
YT9110CJHC      device
c:\>

認識されていない場合とかに、adbプロセスを再起動

adb kill-server && adb start-server
※これを記載した adb-restartとか作っておくと便利

result
c:\>adb kill-server && adb start-server
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
c:\>

端末にログインする

adb shell

result
c:\>adb shell
shell@SO-02G:/ $ exit
c:\>

端末のアクティビティ状態をモニタリングする

adb shell am monitor

result
c:\>adb shell am monitor
Monitoring activity manager...  available commands:
(q)uit: finish monitoring
** Activity starting: com.android.chrome
** Activity starting: com.android.chrome
** Activity starting: com.android.systemui
** Activity starting: com.google.android.googlequicksearchbox
^C
c:\>

インストールパッケージの確認

adb shell pm list packages

result
c:\>adb shell pm list packages chrome
package:com.android.partnerbrowsercustomizations.chromeHomepage.res.overlay_305
package:com.android.partnerbrowsercustomizations.chromeHomepage
package:com.android.chrome
c:\>

パッケージのインストール

ローカルにあるファイルからインストールする場合
adb install <APKファイル>

result
c:\>adb install prod_app-release.apk
3195 KB/s (4904805 bytes in 1.499s)
        pkg: /data/local/tmp/prod_app-release.apk
Success
c:\>

端末上に転送済のファイルからインストールする場合
adb shell pm install <APKファイル名>

result
c:\>adb shell pm install /sdcard/prod_app-release.apk
        pkg: /sdcard/prod_app-release.apk
Success
c:\>

ファイルの転送

ローカルから端末へ
adb push <ローカルファイル> <端末側ファイル>

result
c:\>adb push prod_app-release.apk /sdcard/prod_app-release.apk
2728 KB/s (4904805 bytes in 1.755s)
c:\>

端末からローカルへ
adb pull <端末側ファイル> <ローカルファイル>

result
c:\>adb pull /sdcard/prod_app-release.apk prod_app-release.apk
3537 KB/s (4904805 bytes in 1.354s)
c:\>

パッケージのアンインストール

adb uninstall <パッケージ名>

result
c:\>adb uninstall com.sample.app
Success
c:\>

adb shell pm uninstall <パッケージ名>

result
c:\>adb shell pm uninstall com.sample.app
Success
c:\>

ログ表示(logcat)

adb shell logcat

イベント送信

テキスト入力
adb shell input text <メッセージ>

result
c:\>adb shell input text message
// 端末側にmessageというテキストが送信されます
c:\>

キー(HOME)送信
adb shell input keyevent 3

result
c:\>adb shell input keyevent 3
// 端末側でHOMEキー押下が送信されます
c:\>

※その他のキーコードは
 http://developer.android.com/intl/ja/reference/android/view/KeyEvent.html

intent

インテント直で投げる
adb shell am start -n <パッケージ名>/<アクティビティクラス>

result
c:\>adb shell am start -n com.sample.app/.MainActivity
Starting: Intent { cmp=com.sample.app/.MainActivity }
c:\>

端末にまかせる
adb shell am start -a <アクション> -d <URL>

result
c:\>adb shell am start -a android.intent.action.VIEW -d http://www.google.com/
Starting: Intent { act=android.intent.action.VIEW dat=http://www.google.com/ }
// http:なのでブラウザが起動します
c:\>
result
c:\>adb shell am start -a android.intent.action.VIEW -d market://details?id=com.sample.app
Starting: Intent { act=android.intent.action.VIEW dat=market://details?id=com.sample.app }
// market:なのでGoogle Playが起動します
c:\>

※<アクション>の部分は他に「android.intent.action.SEND」などがあります

broadcast

adb shell am broadcast -a <アクション>

result
// 電源低下通知
adb shell am broadcast -a android.intent.action.BATTERY_LOW
// 起動完了通知(やってみたら再起動しちゃった( ;´Д`))
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

まとめ

コマンドラインでの操作をバッチ化するなどして
まとめておくと結構便利です

下記を参考に作成しました
http://developer.android.com/intl/ja/tools/help/shell.html

73
74
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
73
74