Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lidgnulinux/eca51c04b1596790ab53694e4fd0436d to your computer and use it in GitHub Desktop.
Save lidgnulinux/eca51c04b1596790ab53694e4fd0436d to your computer and use it in GitHub Desktop.
How to build static android-platform-tools without GO.

Build Static Android Platform Tools without GO.

Some days ago, I found an interesting repository about android tools which can be built without GO compiler (check it here). If you're familiar with adb, fastboot, etc, you know what I'm talking about. It suits me because I have no GO compiler or won't bother to download one because I already have GCC. After firts successful build which result on dynamic linked binaries, I'm curious on building the static linked one. Here is how I did it !

Preparations

Before we go deep into building stuffs, we need to prepare some stuffs.

  • Make sure you have GCC / Clang !

  • Satisfy the dependencies, check on the README !

  • Make sure you rebuild these package and enable their static option ! Be careful, some these libs will probably mess your system if you don't know what you're doing !

    • abseil-cpp.
    • brotli, use -DBUILD_SHARED_LIBS=OFF option.
    • fmt, use -DBUILD_SHARED_LIBS=OFF option.
    • lz4.
    • protobuff, use -DBUILD_SHARED_LIBS=OFF option.
    • zlib, use and add --static option when configure the build.
    • zstd.
    • libusb, use and add --enable-static option when configure the build.

Steps

These are some steps to build static android tools :

  1. Get the source code ! You can get it here for 35.0.2 version.

  2. Modify the CmakeLists.txt file ! Add these line after line contain project(android-tools) !

    set(BUILD_SHARED_LIBS OFF)
    set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
    set(CMAKE_EXE_LINKER_FLAGS "-static")
    
  3. Do the regular build as the README suggest !

    $ mkdir build && cd build
    $ cmake ..
    $ make
    
  4. Check if resulted executables are static linked, you can check at build/vendor directory !

    $ cd ..
    $ file build/vendor/adb		# adb, for example
    

    You should get this line :

    build/vendor/adb: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment