Unable to establish a connection to adb

1.0 Problem

After opening an Android project in Studio running under Ubuntu 15.04 Linux, the following error was displayed,

Unable to establish a connection to adb. This usually happens if you have an incompatible version of adb running already. Try reopening Studio after killing any existing adb daemon.

2.0 Analysis

  1. Running the ps -ef | grep adb command does not show any running adb daemon.
  2. Android Studio was started from a terminal. The terminal window shows the error, E/adb: Unexpected exception 'Cannot run program "/home/user1/Android/Sdk/platform-tools/adb": error=2, No such file or directory' while attempting to get adb version from '/home/user1/Android/Sdk/platform-tools/adb'.
  3. The ls -ls /home/user1/Android/Sdk/platform-tools/adb command lists the file but the execution of the command, /home/user1/Android/Sdk/platform-tools/adb, gives the error, bash: /home/user1/Android/Sdk/platform-tools/adb: No such file or directory.
  4. The command, file /home/user1/Android/Sdk/platform-tools/adb gives the output, adb: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped. The problem is that we have a 32-bit program which we are trying run under 64-bit Linux.

3.0 Solution

The solution is to install packages which facilitate running 32-bit programs under 64-bit Linux using the commands,

$ sudo dpkg --add-architecture i386
$ sudo apt-get update
$ sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386

After this, Android Studio connects with adb and works fine.