Installing an Android application package (an apk-file) when developing an android application should be a rather trivial task. However, there are a few tweaks needed to make it work in Linux. This note describes how you install Android apk-files on a device from a Linux host. I have followed this procedure on ArchLinux and on Ubuntu.

In order to proceed you need Android SDK installed on the Linux host.

Turn on Developer mode on your Android phone

You need to turn on developer mode and allow usb-debugging. The way this is done may depend on the Android device used.

On Motorola Moto e6 (running Android 9) you go to settings, then System, advanced -> About phone then hit Build number multiple times.

When developer mode is turned on there should be a new menu option in Settings -> system -> Developer options where you can scroll down to Debugging and enable USB Debugging.

alt attribute

No permissions for device

When you plug your device you can use adb (available from Android SDK) to list devices.

$ adb devices -l
List of devices attached
ZE2222MG7R             no permissions; see [] usb:2-2 transport_id:1

as seen there are no permission to install an application via adb on the connected device. This can be solved by adding a udev rule.

USB device id

To create the udev rule the the USB Device id is needed so let’s list the device id using lsusb (this can also be found in dmesg when the device is connected)

$ lsusb
Bus 002 Device 006: ID 0e8d:201c MediaTek Inc. moto e6 play

Here the vendor id is 0e8d and the product id is 201c.

Adding udev rule

Create a rules file for Android in /etc/udev/rules.d/51-android.rules and add the line

SUBSYSTEM=="usb", ATTR{idVendor}=="0e8d", ATTR{idProduct}=="201c", MODE="0660", OWNER="bjorn"

Now reload udev

$ sudo udevadm control --reload

Disconnect and reconnect the device.

Now list devices again

$ adb devices -l
List of devices attached
ZE2222MG7R             unauthorized usb:2-2 transport_id:6

There should be a pop-up dialog on the device asking you to allow USB debugging.

alt attribute

Authorize and list devices again

$ adb devices -l
List of devices attached
ZE2222MG7R             device usb:2-2 product:bali_reteu model:moto_e6_play device:bali transport_id:7

Now you should be allowed to install applications on the device using adb

Installing the app

Now you can install the app using Android Studio or via adb. In adb you will probably need to allow installing test packages, so add the -t flag.

$ adb install -t <package>

If you already have the package installed and want to replace the existing, add the -r flag

$ adb install -t -r <package>