Android adb devices linux

Android Debug Bridge

The 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.

Installation

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

Usage

Connect device

  • 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.
  • Many devices’ udev rules are included in 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.

To connect to a real device or phone via ADB under Arch, you must:

  1. You might want to install android-udev if you wish to connect the device to the proper /dev/ entries.
  2. plug in your android device via USB.
  3. 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. Check allowing it permanently option will copy ~/.android/adbkey.pub to the target phone’s /data/misc/adb/adb_keys location.
    • 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.

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.

Читайте также:  Adobe reader linux аналоги

Figure out device IDs

Each Android device has a USB vendor/product ID. An example for HTC Evo is:

vendor id: 0bb4 product id: 0c8d

Plug in your device and execute:

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

Adding udev rules

If your device is not included in android-udev (or android-udev-git AUR ), use the following template to create a custom udev rule by replacing [VENDOR ID] and [PRODUCT ID] with the IDs of your device.

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

Detect the device

After you have setup the udev rules, unplug your device and replug it.

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

If adb devices still shows unauthorized next to your device, make sure that that device has debugging permission allowed on the device itself. A Allow USB Debugging? dialog should be presented when you physically connect the device. Select Always Allow. , then tap OK. If the dialog was never presented, try Settings > Developer Options > Revoke USB Debugging Authorizations, then tap OK, and repeat the steps in this section. If you still do not see the Allow USB Debugging? dialog, and the device is listed as unauthorized, then enter the Developer Options on the device and first uncheck USB Debugging and then check it again.

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 

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.

Читайте также:  Log in linux command line

The command to create a backup is:

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

The command parameters list is:

adb backup [-f ] [-apk|-noapk] [-shared|-noshared] [-all] [-system|nosystem] []

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 backupFileName.ab 

Note: Remember that restoring operation will replaces your device contents with the backup contents.

Tools building on ADB

  • adbfs-rootless-gitAUR – mount an Android device connected via USB.
  • adb-sync-gitAUR – a tool to synchronize files between a PC and an Android device using the ADB protocol.
  • androidscreencast-binAUR – view and control your Android device via ADB from a PC.
  • logcat-colorAUR – a colorful and highly configurable alternative to the standard adb logcat command.
  • scrcpy – display and control your Android device.
  • qtscrcpyAUR – Android real-time display control software.

Troubleshooting

Empty device list

A possible cause for your device not showing up is not having enabled USB debugging on your device. See enable USB debugging.

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 #Adding udev rules.

Источник

How to usb-connect android devices with adb under ubuntu [closed]

you probably run into the same problem like me. However, I found on the internet some more or less sub optimal solutions The basic idea is to start adb as root. The solutions I found were cumbersome. One proposal is to start adb per sudo. An other proposal was to set up a boot script in /etc/init.d My solution is to give adb the permission to start as root. To do so, switch to root

sudo bash chown root adb chmod ug+s-w adb 
sudo chown root adb sudo chmod ug+s-w adb 

Please do not do this! The authors of the adb program did not intend for its development machine side to be run as root, but rather to use a udev rule to allow access to listed device types only. Trusting a program more than its authors recommend is a bad idea! Also, voting to close as there’s not actually a question stated, while the topic has already been covered numerous times.

Читайте также:  Linux удалить файл в терминале

2 Answers 2

The Google recommended way to deal with ADB device permissions is to create an UDEV rule which would set appropriate permissions on device enumeration.

If you’re developing on Ubuntu Linux, you need to add a udev rules file that contains a USB configuration for each type of device you want to use for development. In the rules file, each device manufacturer is identified by a unique vendor ID, as specified by the ATTR property. For a list of vendor IDs, see USB Vendor IDs, below. To set up device detection on Ubuntu Linux: Log in as root and create this file: /etc/udev/rules.d/51-android.rules. Use this format to add each vendor to the file: SUBSYSTEM==»usb», ATTR==»0bb4″, MODE=»0666″, GROUP=»plugdev»

In this example, the vendor ID is for HTC. The MODE assignment specifies read/write permissions, and GROUP defines which Unix group owns the device node. Note: The rule syntax may vary slightly depending on your environment. Consult the udev documentation for your system as needed. For an overview of rule syntax, see this guide to writing udev rules. Now execute: chmod a+r /etc/udev/rules.d/51-android.rules When plugged in over USB, can verify that your device is connected by executing adb devices from your SDK platform-tools/ directory. If connected, you’ll see the device name listed as a «device.»

Источник

Оцените статью
Adblock
detector