Aapo Rantalainen's blog

Experiences with Information Technology and Open source

Building adb for Ubuntu without whole SDK

Posted by Aapo Rantalainen on December 5, 2015

This post is upgrade for my previous post about building ADB for Ubuntu: https://aaporantalainen.wordpress.com/2015/03/04/newer-adb-for-ubuntu-with-sideloading/


Adb (Android Debug Bridge) is debugging tool to communicate with Android-device and host.


Developer can install whole Android SDK and get adb. But I think adb should be possible to build alone. Ubuntu/Debian has package android-tools-adb, which contains adb, but it will never be newest version.

How to

This is not the newest version (because at that point it will start using source code from other part of SDK). Code is somewhere between Android-5.1.1_r29 and Android-6.0.0_r1.

#Needed tools
sudo apt-get install zlib1g-dev libssl-dev git make gcc
#Download source code (about 32MB, 2015-12-05)
git clone https://android.googlesource.com/platform/system/core
cd core/adb

#Change last working commit (after that more code needed. This was made 2015-04-17)
git checkout 0b8ecb32908f0ccde550dd510f4a562239085806

#Create Makefile
echo -e '
# standalone Makefile for adb
SRCS_CPP+= adb.cpp
SRCS_CPP+= adb_auth.cpp
SRCS_CPP+= adb_io.cpp
SRCS_CPP+= adb_listeners.cpp
SRCS_CPP+= sockets.cpp
SRCS_CPP+= transport.cpp
SRCS_CPP+= transport_local.cpp
SRCS_CPP+= transport_usb.cpp
SRCS_CPP+= fdevent.cpp
SRCS_CPP+= get_my_path_linux.cpp
SRCS_CPP+= usb_linux.cpp
SRCS_CPP+= adb_auth_host.cpp
SRCS_CPP+= services.cpp
SRCS_CPP+= adb_main.cpp
SRCS_CPP+= console.cpp
SRCS_CPP+= commandline.cpp
SRCS_CPP+= adb_client.cpp
SRCS_CPP+= file_sync_client.cpp

SRCS+= ../libcutils/socket_inaddr_any_server.c
SRCS+= ../libcutils/socket_local_client.c
SRCS+= ../libcutils/socket_local_server.c
SRCS+= ../libcutils/socket_loopback_client.c
SRCS+= ../libcutils/socket_loopback_server.c
SRCS+= ../libcutils/socket_network_client.c
SRCS+= ../libcutils/load_file.c
CPPFLAGS+= -I../include

CXXFLAGS+= -fpermissive -std=c++11

LIBS= -lcrypto -lpthread -lrt -lz 
CC= gcc
LD= g++
OBJS= $(SRCS:.c=.o)
OBJS_CPP= $(SRCS_CPP:.cpp=.o)
all: adb
adb: $(OBJS) $(OBJS_CPP)
\t$(LD) -o $@ $(LDFLAGS) $(OBJS) $(OBJS_CPP) $(LIBS) 
\trm -rf *.o ../libcutils/*.o adb
' > standalone_Makefile

make -f standalone_Makefile

./adb --version
#Android Debug Bridge version 1.0.32

You will get several warnings:

warning: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]

3 Responses to “Building adb for Ubuntu without whole SDK”

  1. Anonymous said

    It’s working

  2. […] 下一步考虑从按此方法从源码编译来运行最新版的adb。 […]

  3. […] Building adb for Ubuntu without whole SDK […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: