0
0

More than 1 year has passed since last update.

adb コマンド

Last updated at Posted at 2021-11-22

この記事では、よく使う adb コマンドをまとめます。
Android Debug Bridge version 1.0.41
Version 31.0.3-7562133

######adb が使用可能な(adb サーバーに接続している)デバイス(シリアル番号)の確認
adb devices

$ adb devices
List of devices attached
emulator-5556   device

adb を使用する際に、デバイスが複数接続されている場合は、コマンドを送るデバイスのシリアル番号を -s (use device with given serial) で指定します。

adb -s emulator-5554 ...

######アプリのインストール
adb install [apkのパス]

$ adb install app-debug.apk
adb: failed to install app-debug.apk: Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]
-t

上記のようなエラーが出る場合は、-t(allow test packages)を付加します。

$ adb install -t app-debug.apk
Performing Streamed Install
Success

######デバイスからファイル/ディレクトリをコピーする
adb pull [コピー対象のパス] [コピー先のパス]
例:デバイス上の data/data/com.sample.app/log.txt ファイルを PC の test フォルダにコピーする場合

adb pull data/data/com.sample.app/log.txt test

######デバイスにファイルをコピーする
adb push [コピー対象のパス] [コピー先のパス]
例:PC 上の log.txt ファイルをデバイスの data/data/com.sample.app/ フォルダにコピーする場合

adb push log.txt data/data/com.sample.app/

######アプリ起動
adb shell am start -n [パッケージ名プレフィックス付きのコンポーネント名]

adb shell am start -n com.sample.app/com.sample.app.MainActivity

######アプリ停止
adb shell am force-stop [パッケージ名]

adb shell am force-stop com.sample.app

######アプリのキャッシュ削除
adb shell pm clear [パッケージ名]

adb shell pm clear com.sample.app

######Activityの状態確認
下記のコマンドは、フォーカスロスト等の不具合解析時、Activityの状態を確認するのに役立ちます。

adb shell dumpsys activity top

出力内容のView Hierarchyの部分には、Viewの状態(表示状態や位置、フォーカスの有無)が出力されます。

下記の場合は、MainActivityのListViewにフォーカスが当たっていることがわかります。
詳細な見方は、別の記事に記載しています。

...
    View Hierarchy:
      DecorView@1f98dbe[MainActivity]
        android.widget.LinearLayout{f656e1f V.E...... ........ 0,0-1080,2148}
          android.view.ViewStub{b7856c G.E...... ......I. 0,0-0,0 #10201af android:id/action_mode_bar_stub}
          android.widget.FrameLayout{652e735 V.E...... ........ 0,171-1080,2148}
            androidx.appcompat.widget.ActionBarOverlayLayout{bbcc7ca V.E...... ........ 0,0-1080,1977 #7f080065 app:id/decor_content_parent}
              androidx.appcompat.widget.ContentFrameLayout{47ccd3b V.E...... ........ 0,154-1080,1977 #1020002 android:id/content}
                androidx.constraintlayout.widget.ConstraintLayout{64d8c58 V.E...... ........ 0,0-1080,1823 #7f08009d app:id/main}
                  android.widget.ListView{3d7c1b1 VFED.VC.. .F...... 0,0-1080,1823 #7f0800cb app:id/sampleList aid=1073741824}
...

######キーイベントを送る
デバイスに対してキー操作を行う場合は下記のコマンドで、キーイベントを送ることが出来ます。

例:十字キーの下のイベントを送る場合

adb shell input keyevent KEYCODE_DPAD_DOWN

キーコードはKeyEventに記載があります。

######バグレポートを取得する
バグレポートには、logcat や実行されているスレッドの情報などが含まれ、不具合の解析に役立ちます。
※ スレッドの不具合解析は別の記事に記載しています。

adb bugreport
0
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
0
0