2013-06-07

64-bit Linux ADB for Simulator

Thanks to the efforts of new Mozilla intern Brandon Kase, the latest preview build of Firefox OS Simulator for Linux includes a 64-bit version of ADB, so you can push an app to an FxOS device from 64-bit Linux installations without any extra packages!

Building it was tricky, because the Android SDK build scripts don't support that target. Brandon first tried simply specifying the target, which worked on an older version of ADB (1.0.24). But it failed on the latest version (1.0.31), which links with a bundled copy of libcrypto that includes 32-bit assembly.

Ubuntu 13.04 (Raring) ships a 64-bit android-tools-adb package, though, so we knew it could be done. And its source package's build system is much simpler than the SDK's. We just needed a binary that works on distributions with older versions of glibc than Raring's 2.17. And one that doesn't depend on a specific version of libcrypto, which varies around the Linux world; whereas Raring's ADB executable appears to need the specific version that comes with that distribution.

So Brandon modified the source package's Makefile to link libcrypto statically (note the absolute path to libcrypto.a, which may vary):
--- debian/makefiles/adb.mk    2013-03-26 14:15:41.000000000 -0700
+++ adb-static-crypto.mk    2013-06-06 16:51:52.794521267 -0700
@@ -40,15 +40,16 @@
 CPPFLAGS+= -I.
 CPPFLAGS+= -I../include
 CPPFLAGS+= -I../../../external/zlib
+CPPFLAGS+= -I/usr/include/openssl
 
-LIBS+= -lc -lpthread -lz -lcrypto
+LIBS+= -lc -lpthread -lz -ldl
 
 OBJS= $(SRCS:.c=.o)
 
 all: adb
 
 adb: $(OBJS)
-    $(CC) -o $@ $(LDFLAGS) $(OBJS) $(LIBS)
+    $(CC) -o $@ $(LDFLAGS) $(OBJS) /usr/lib/x86_64-linux-gnu/libcrypto.a $(LIBS)
 
 clean:
     rm -rf $(OBJS) adb

Then I copied the source package to my CentOS 16 build machine (which has glibc 2.12) and built it there. After which the resultant executable worked on all the distributions we tested: Ubuntu 13.04, Ubuntu 10.04, CentOS 16, and Arch Linux (kernel 3.9.3-1-ARCH).

Presumably it will work on others too. But if it still doesn't work for you, let us know!

And if you just want the ADB executable, sans Simulator, here it is.

2 comments:

Anonymous said...

CentOS 16...? :-)

Anonymous said...

How did you get through an entire post about ADB without mentioning it stands for "Android Debug Bridge"?