「Android Debug Bridge」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(英語版より転載)
 
(→‎動作するか確認: 不足している記述を英語版より転載)
 
(同じ利用者による、間の9版が非表示)
3行目: 3行目:
 
[[en:Android Debug Bridge]]
 
[[en:Android Debug Bridge]]
 
[[pt:Android Debug Bridge]]
 
[[pt:Android Debug Bridge]]
The [https://developer.android.com/studio/command-line/adb Android Debug Bridge] (ADB) is a command-line tool that can be used to install, uninstall and debug apps, transfer files and access the device's shell.
+
[https://developer.android.com/studio/command-line/adb Android Debug Bridge] (ADB) はコマンドラインツールで、アプリのインストール、アンインストール、デバッグ、ファイルの転送、デバイスのシェルへのアクセスなどを行うことができます。
   
 
== Installation ==
 
== Installation ==
11行目: 11行目:
 
== Usage ==
 
== Usage ==
   
=== Connect device ===
+
=== 実機に接続 ===
   
 
{{Tip|
 
{{Tip|
  +
* デバイスによっては、ADB を動作させる前に、デバイスの [[MTP]] を有効にする必要があります。また、PTP モードを有効にする必要があるデバイスもあります。
* For some devices, you may have to enable [[MTP]] on the device, before ADB will work. Some other devices require enable PTP mode to work.
 
  +
* 大抵のデバイスは {{Pkg|libmtp}} に udev ルールが含まれているため、パッケージがインストールされていれば、ルールの追加は必要ありません。
* Many devices' [[udev]] rules are included in {{Pkg|libmtp}}, so if you have this installed, the following steps may not be necessary.
 
 
* Make sure your USB cable is capable of both charge and data. Many USB cables bundled with mobile devices do not include the USB data pin.
 
* Make sure your USB cable is capable of both charge and data. Many USB cables bundled with mobile devices do not include the USB data pin.
 
}}
 
}}
   
  +
ADB で Arch 下の実機やスマートフォンに接続するには、以下を実行する必要があります:
To connect to a real device or phone via ADB under Arch, you must:
 
   
  +
# 適当な {{ic|/dev/}} エントリにデバイスを接続するには {{Pkg|android-udev}} もインストールする必要があります。
# You might want to install {{Pkg|android-udev}} if you wish to connect the device to the proper {{ic|/dev/}} entries.
 
  +
# USB で Android デバイスを接続する。
# plug in your android device via USB.
 
  +
# スマートフォンやデバイスで USB デバッグを有効にする。
# Enable USB Debugging on your phone or device:
 
  +
#* Jelly Bean (4.2) 以降: {{ic|設定 --> 端末情報}} を開いてデベロッパーになったというポップアップが表示されるまで “Build Number” をタップ (約10回連打)。そして {{ic|設定 --> 開発者向けオプション --> USB デバッグ}} から USB デバッグを有効にする。デバイスはフィンガープリントを使ってコンピュータに接続しても良いか聞いてきます。永続的に許可すると {{ic|$HOME/.android/adbkey.pub}} がデバイスの {{ic|/data/misc/adb/adb_keys}} フォルダにコピーされます。
#* Jelly Bean (4.2) and newer: Go to ''Settings > About Phone'' tap ''Build Number'' 7 times until you get a popup that you have become a developer. Build number may be under a menu called ''Software info'' on newer Android OS versions. Then go to ''Settings > Developer > USB debugging'' and enable it. The device will ask to allow the computer with its fingerprint to connect. Allowing it permanently will copy {{ic|~/.android/adbkey.pub}} onto the devices {{ic|/data/misc/adb/adb_keys}} folder.
 
  +
#* 古いバージョン: {{ic|設定 --> アプリケーション --> 開発 --> USB デバッグ}} から有効にできます。このオプションにチェックを入れた後はスマートフォンを再起動して USB デバッグを有効にしてください。
#* Older versions: This is usually done from ''Settings > Applications > Development > USB debugging''. Reboot the phone after checking this option to make sure USB debugging is enabled.
 
   
  +
[[#動作するか確認|ADB がデバイスを認識]]したら (IDE からアクセスできる状態)、完了です。認識しない場合は以下を見て下さい。
If [[#Detect the device|ADB recognizes your device]] ({{ic|adb devices}} shows it as {{ic|"device" and not as "unauthorized"}}, or it is visible and accessible in IDE), you are done. Otherwise see the instructions below.
 
   
=== Figure out device IDs ===
+
==== デバイス ID を確かめる ====
   
Each Android device has a USB vendor/product ID. An example for HTC Evo is:
+
それぞれの Android デバイスには USB ベンダー・プロダクト ID が存在します。例えば HTC Evo なら:
   
 
vendor id: 0bb4
 
vendor id: 0bb4
 
product id: 0c8d
 
product id: 0c8d
   
  +
デバイスを接続して次を実行してください:
Plug in your device and execute:
 
   
 
$ lsusb
 
$ lsusb
   
  +
以下のように表示されるはずです:
It should come up something like this:
 
   
 
Bus 002 Device 006: ID 0bb4:0c8d High Tech Computer Corp.
 
Bus 002 Device 006: ID 0bb4:0c8d High Tech Computer Corp.
   
=== Adding udev rules ===
+
=== udev ルールを追加する ===
   
Use the rules from {{Pkg|android-udev}} (or {{Aur|android-udev-git}}), install them manually from [https://source.android.com/source/initializing#configuring-usb-access Android developer], or use the following template for your [[udev rules]], just replace {{ic|[VENDOR ID]}} and {{ic|[PRODUCT ID]}} with yours. Copy these rules into {{ic|/etc/udev/rules.d/51-android.rules}}:
+
{{Pkg|android-udev}} (または {{Aur|android-udev-git}}) をインストールするか手動で [http://source.android.com/source/initializing.html#configuring-usb-access Android developer] のルールを使うか、あるいは以下のテンプレートを使って udev ルールを作って下さい。[VENDOR ID] [PRODUCT ID] はあなたの ID に置き換えて下さい。ルールを {{ic|/etc/udev/rules.d/51-android.rules}} にコピー:
   
{{hc|/etc/udev/rules.d/51-android.rules|2=<nowiki>
+
{{hc|/etc/udev/rules.d/51-android.rules|2=<nowiki>SUBSYSTEM=="usb", ATTR{idVendor}=="[VENDOR ID]", MODE="0660", GROUP="adbusers"
SUBSYSTEM=="usb", ATTR{idVendor}=="[VENDOR ID]", MODE="0660", GROUP="adbusers"
 
 
SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_adb"
 
SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_adb"
SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_fastboot"
+
SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_fastboot"</nowiki>}}
</nowiki>}}
 
 
Then, to reload your new udev rules, execute:
 
   
  +
そして、新しい udev ルールをリロードするために、次を実行:
 
# udevadm control --reload-rules
 
# udevadm control --reload-rules
   
  +
使用しているユーザーを {{ic|adbusers}} [[ユーザーとグループ|グループ]]に追加することで {{ic|adb}} デバイスにアクセスできるようになります。
Make sure you are member of {{ic|adbusers}} [[user group]] to access {{ic|adb}} devices.
 
   
=== Detect the device ===
+
==== 動作するか確認 ====
   
  +
udev ルールを設定したら、デバイスのプラグを一度抜いてから再接続してください。
After you have setup the udev rules, unplug your device and replug it.
 
   
  +
次のコマンドを実行すれば:
After running:
 
   
 
$ adb devices
 
$ adb devices
   
  +
以下のように表示されるはずです:
you should see something like:
 
   
 
List of devices attached
 
List of devices attached
79行目: 76行目:
 
$ adb devices
 
$ adb devices
   
=== Transferring files ===
+
=== ファイル転送 ===
 
You can now use adb to transfer files between the device and your computer. To transfer files to the device, use
 
   
  +
adb を使ってデバイスとコンピュータ間でファイルを転送することができます。ファイルをデバイスに送信するには次のコマンドを使用:
 
$ adb push ''<what-to-copy>'' ''<where-to-place>''
 
$ adb push ''<what-to-copy>'' ''<where-to-place>''
   
  +
ファイルを受信するには:
To transfer files from the device, use
 
 
 
$ adb pull ''<what-to-pull>'' ''<where-to-place>''
 
$ adb pull ''<what-to-pull>'' ''<where-to-place>''
   
Also see [[#Tools building on ADB]].
+
[[#Tools building on ADB]] も参照してください。
   
 
=== Backup and restore ===
 
=== Backup and restore ===

2020年8月6日 (木) 09:45時点における最新版

Android Debug Bridge (ADB) はコマンドラインツールで、アプリのインストール、アンインストール、デバッグ、ファイルの転送、デバイスのシェルへのアクセスなどを行うことができます。

Installation

ADB is part of the Platform-Tools SDK package and the android-tools package.

Usage

実機に接続

ヒント:
  • デバイスによっては、ADB を動作させる前に、デバイスの MTP を有効にする必要があります。また、PTP モードを有効にする必要があるデバイスもあります。
  • 大抵のデバイスは libmtp に udev ルールが含まれているため、パッケージがインストールされていれば、ルールの追加は必要ありません。
  • Make sure your USB cable is capable of both charge and data. Many USB cables bundled with mobile devices do not include the USB data pin.

ADB で Arch 下の実機やスマートフォンに接続するには、以下を実行する必要があります:

  1. 適当な /dev/ エントリにデバイスを接続するには android-udev もインストールする必要があります。
  2. USB で Android デバイスを接続する。
  3. スマートフォンやデバイスで USB デバッグを有効にする。
    • Jelly Bean (4.2) 以降: 設定 --> 端末情報 を開いてデベロッパーになったというポップアップが表示されるまで “Build Number” をタップ (約10回連打)。そして 設定 --> 開発者向けオプション --> USB デバッグ から USB デバッグを有効にする。デバイスはフィンガープリントを使ってコンピュータに接続しても良いか聞いてきます。永続的に許可すると $HOME/.android/adbkey.pub がデバイスの /data/misc/adb/adb_keys フォルダにコピーされます。
    • 古いバージョン: 設定 --> アプリケーション --> 開発 --> USB デバッグ から有効にできます。このオプションにチェックを入れた後はスマートフォンを再起動して USB デバッグを有効にしてください。

ADB がデバイスを認識したら (IDE からアクセスできる状態)、完了です。認識しない場合は以下を見て下さい。

デバイス ID を確かめる

それぞれの Android デバイスには USB ベンダー・プロダクト ID が存在します。例えば HTC Evo なら:

vendor id: 0bb4
product id: 0c8d

デバイスを接続して次を実行してください:

$ lsusb

以下のように表示されるはずです:

Bus 002 Device 006: ID 0bb4:0c8d High Tech Computer Corp.

udev ルールを追加する

android-udev (または android-udev-gitAUR) をインストールするか手動で Android developer のルールを使うか、あるいは以下のテンプレートを使って udev ルールを作って下さい。[VENDOR ID] と [PRODUCT ID] はあなたの ID に置き換えて下さい。ルールを /etc/udev/rules.d/51-android.rules にコピー:

/etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="[VENDOR ID]", MODE="0660", GROUP="adbusers"
SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_adb"
SUBSYSTEM=="usb",ATTR{idVendor}=="[VENDOR ID]",ATTR{idProduct}=="[PRODUCT ID]",SYMLINK+="android_fastboot"

そして、新しい udev ルールをリロードするために、次を実行:

# udevadm control --reload-rules

使用しているユーザーを adbusers グループに追加することで adb デバイスにアクセスできるようになります。

動作するか確認

udev ルールを設定したら、デバイスのプラグを一度抜いてから再接続してください。

次のコマンドを実行すれば:

$ adb devices

以下のように表示されるはずです:

List of devices attached 
HT07VHL00676    device

If adb still does not detect the device after plugging your device back in, kill and restart the adb server as root and check devices again:

# adb kill-server
# adb start-server
$ adb devices

ファイル転送

adb を使ってデバイスとコンピュータ間でファイルを転送することができます。ファイルをデバイスに送信するには次のコマンドを使用:

$ adb push <what-to-copy> <where-to-place>

ファイルを受信するには:

$ adb pull <what-to-pull> <where-to-place>

#Tools building on ADB も参照してください。

Backup and restore

You can also backup and restore your device with adb. Moreover, no root is required to follow the process. The commands below led to backup your device to a single file which can also be successively restored.

The command to create a backup is

$ adb backup -apk -shared -all -f backupFileName.ab

The command parameters list is

adb backup [-f <file>] [-apk|-noapk] [-shared|-noshared] [-all] [-system|nosystem] [<packages...>]

Then confirm the process on your device's display and provide a password whether a backup password has been set before.

The command to restore a previous backup is

$ adb restore mybackup.ab
ノート: Remember that restoring replaces your device contents with the backup.

Tools building on ADB

Troubleshooting

Empty device list

A possible cause for your device not showing up is not having enabled USB debugging on your device. You can do that by going to Settings > Applications > Development and enabling USB debugging. Since Android 4.2 (Jelly Bean), the development menu is hidden; to enable it go to Settings > About phone and tap Build number 7 times.

No permissions error

If the device shows up with a "no permissions" label, it probably has a different vendor/product ID with respect to the ones collected by android-udev.

This can happen for instance when the device uses a custom ROM, or when it is switched from MTP to USB tethering mode, sideload and/or fastboot mode. Verify the actual device's ID with lsusb and add the appropriate udev rules as described above.