「Android Debug Bridge」の版間の差分
Kusanaginoturugi (トーク | 投稿記録) (→Adding udev rules: 分割前の記事 Android#Android_Debug_Bridge_.28ADB.29 より転載) |
Kusanaginoturugi (トーク | 投稿記録) |
||
11行目: | 11行目: | ||
== Usage == |
== Usage == |
||
− | === |
+ | === 実機に接続 === |
{{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. |
||
}} |
}} |
2020年8月4日 (火) 10:13時点における版
Android Debug Bridge (ADB) はコマンドラインツールで、アプリのインストール、アンインストール、デバッグ、ファイルの転送、デバイスのシェルへのアクセスなどを行うことができます。
目次
Installation
ADB is part of the Platform-Tools SDK package and the android-tools package.
Usage
実機に接続
To connect to a real device or phone via ADB under Arch, you must:
- You might want to install android-udev if you wish to connect the device to the proper
/dev/
entries. - plug in your android device via USB.
- Enable USB Debugging on your phone or device:
- 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
~/.android/adbkey.pub
onto the devices/data/misc/adb/adb_keys
folder. - 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.
- 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
If ADB recognizes your device (adb devices
shows it as "device" and not as "unauthorized"
, or it is visible and accessible in IDE), you are done. Otherwise see the instructions below.
デバイス 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
デバイスにアクセスできるようになります。
Detect the device
After you have setup the udev rules, unplug your device and replug it.
After running:
$ adb devices
you should see something like:
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
Transferring files
You can now use adb to transfer files between the device and your computer. To transfer files to the device, use
$ adb push <what-to-copy> <where-to-place>
To transfer files from the device, use
$ adb pull <what-to-pull> <where-to-place>
Also see #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
Tools building on ADB
- adbfs-rootless-gitAUR - a FUSE filesystem over ADB
- adb-sync (available as adb-sync-gitAUR) – a tool to synchronize files between a PC and an Android device using the ADB protocol.
- AndroidScreencast (available as androidscreencast-binAUR) – view and control your Android device from a PC (via ADB).
- logcat-colorAUR - a colorful and highly configurable alternative to the standard
adb logcat
command. - scrcpy (available as scrcpyAUR) – display and control your Android device
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.