How to use adb (Android debugging bridge) on Silverblue?

I’ve tried to use adb in a toolbox container (just install it via dnf install android-tools etc. inside of the container), but it seems it is too isolated from the host, because while it can detect a device, it cannot get a permission. Even in Android’s recovery and with sudo in the container it only shows this:

$ sudo adb devices
List of devices attached
* daemon not running; starting now at tcp:5037
* daemon started successfully
4e1d2a26	no permissions; see [http://developer.android.com/tools/device.html]

So should I just give up and layer it on the host instead, or (how) can I make it work inside of the container?

1 Like

You don’t even need to layer them, as long as you’re okay updating them manually when you need too.

wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
unzip platform-tools-latest-linux.zip
sudo cp -v platform-tools/adb platform-tools/fastboot platform-tools/mke2fs* platform-tools/e2fsdroid /usr/local/bin

To fix perms

git clone https://github.com/M0Rf30/android-udev-rules.git
cd android-udev-rules
sudo cp -v 51-android.rules /etc/udev/rules.d/51-android.rules
sudo chmod a+r /etc/udev/rules.d/51-android.rules
sudo groupadd adbusers
sudo usermod -a -G adbusers $(whoami)
sudo systemctl restart systemd-udevd.service
adb kill-server
adb devices

The udev rules might actually fix them in toolbox.

10 Likes

Been trying to get fastboot and adb working in a toolbox and getting “no permissions” errors … until I saw this. Both now working, even without sudo, thanks! @pluto

1 Like

Yes this does work when you do this all on the host.

But this still does not solve the problem of doing this in a toolbox/podman container. It does not seem to work in there…

1 Like

For what it’s worth, the android-tools package in Fedora is extremely old (from 2018-08-28) and can cause issues with some phones.

(For example: My old, problematic Nexus 6P doesn’t work fully with fastboot due to the ancient android-tools, when it tries to call mke2fs… but adb still seems generally fine to use, even in the old version Fedora ships.)

So you’d probably want to use @pluto’s method of wget on Fedora anyway… and/or the Android Studio flatpak on Flathub, depending on what you want to do.

(And, yeah, I still don’t know what to tell you about using a podman/toolbox container for this.)

1 Like

Kind of off-topic: Is it safe if I use the package from Fedora repos and not the Google zip? I have a relatively old phone, which is released 6-7 years ago.

If it is that old, likely yes. Depends on the Android version.

Generally, just try it and if everything works (adb backup is easily broken e.g., but won’t tell it), that is all fine.

1 Like

The Nexus 6P, the phone I mentioned above, is nearly 5 years old and has this problem. I was trying to installer newer version of Android (custom ROMs) and also UBports on it, and that’s where I hit the problem with way-too-old android-tools in Fedora.

So, if you’re sticking with stock ROMs (that are extremely out of date at this point), it might be fine. If you want to use something that has been updated in the past few years (and you really should, if you’re actually going to use the device… due to huge security issues in older versions of Android), you might hit the issue when reformatting some filesystems on the device (which is standard on installation of basically any new ROM or Linux-based OS).

1 Like

I also flash custom ROMs on a Xiami Mi 4 and didn’t have any problem so far. I didn’t try to reformat via adb though, I do reformatting via recovery. Adb commands I use so far are push, pull, sideload, remount and shell. I really don’t want to use anything which is compiled and packaged by Google.

In case you’re trying to decide whether or not to trust this third-party repository from “M0Rf30”, know that it is the upstream source for the android-sdk-platform-tools-common Ubuntu package. See here and here.


DIY approach

You can also run lsusb while the device is plugged in, locate and copy its vendor code and write your own rule for it at /etc/udev/rules.d/51-android.rules:

# Skip if not connected via USB
SUBSYSTEM!="usb", GOTO="android_usb_rules_end"

LABEL="android_usb_rules_begin"

# Here you replace "18d1" (Google vendor code) with your device's vendor code
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ENV{adb_user}="yes"

# Enable device as a user device if found
ENV{adb_user}=="yes", MODE="0660", GROUP="adbusers", TAG+="uaccess"

LABEL="android_usb_rules_end"

Then you create the group adbusers and add yourself to it. After a reboot adb devices should recognize the device.

1 Like

Hello @crimsonking ,
Welcome to the discussion area and thank you for coming by with gifts!

1 Like