Blog | jessechen.net

Protip: Bash Autocomplete for Android ADB

February 17, 2012 3:00 pm by

Introduction

This is a super quick tip that will only take 1 minute to make your android development so much easier.  Android Debug Bridge (adb) is a command-line tool that lets you interface with an emulator or an android device.  Its great and previously I wrote about how you can debug your Android app wirelessly on your device.  What sucks though is that you can’t tab autocomplete commands (e.g. type ‘adb d’ then tab and bash will autocomplete and fill out ‘adb devices’), which means having to look up adb commands to figure out what you want and/or wasting time by typing the whole command (every ms counts!).

This protip will get you setup with bash autocomplete for ADB in less than 1 minute.  Ready?  Here we go.

Instructions

  • Download the adb bash completion file here from Roman’s repo.  Another good one is here on github by mbrubeck.
  • Store the file somewhere safe.  Anywhere you want. I chose /bin.
  • Use your favorite editor of choice (which should be vim) to edit your ~/.bashrc file.
  • Add the following lines (substitute your own path to the adb bash completion file) to the end of your ~/.bashrc file:
if [ -e /bin/adb.txt ] ; then
     source /bin/adb.txt
fi
  • Save and quit.  In your terminal, type source ~/.bashrc to reload your bash.
  • Check if it works.  Type ‘adb d’ and press tab to see if it autocompletes to ‘adb devices’.

And that’s it!  I’ve been looking for something like this for a long time.  Hope it helps you as much as it did for me. ūüôā

Filed under: Android — Tags: , , , , — Jesse Chen @ 3:00 PM

About

Jesse is a software engineer at Facebook, who just graduated from UC Berkeley. Passionate about mobile technology and entrepreneurship, he started his own blog as a home for his tutorials, projects, and random thoughts. Follow him on Facebook to stay updated on his latest tutorials and projects.


Debugging Your Android App Wirelessly on an Android Smartphone

March 16, 2011 8:20 pm by

Introduction

Developing for Android is very easy to set up and get started on your computer.  However, a gripe shared among others, not just me, is that the Android emulator is too slow.  On my old computer, it would take 1-2 minutes for it to boot up.  In debugging mode, the response time is very slow.

There are two methods:

  1. Connect your phone to your computer and find the drivers online (if needed) to allow adb to recognize your phone as a running Android device.  Eclipse and the ADT plugin will take care of the rest.
  2. The super dumb way is to take the .apk file that your Android project generates every time it compiles (at yourappfolder/bin/yourapp.apk), connect your phone to the computer via USB, push it to your phone, and install.  But that is also very inefficient (and dumb)!  What if you just wanted to test a small change real quick?  You would have to keep your phone tethered to the computer, and constantly overwrite your .apk file and re-install your application each time you wanted to test it on your phone.

I have a way that allows you to test your Android application on your Android smartphone without physically connecting your phone to your computer.  All it requires is a rooted Android smartphone, and a shared wifi network between the computer and the phone.

Note: This method requires a phone with root access, and accessing adb over a wifi network might be a security concern for some. ¬†Take this method for what it’s worth. ¬†If you are doing this on your own home network that is trusted and encrypted there shouldn’t be a problem, but I would avoid doing this in a public wifi network.

Video Walkthrough

What to do on your phone

Make sure you are connected to the same local network that your computer is on via WiFi.  You will then need an app called adbWireless, it allows a rooted phone to allow adb connection to your phone as if it was connected by USB.  Once you install adbWireless and allow root privileges, press the giant red button to begin.

It will provide you with a one-line command to run in your command prompt, something similar to “adb connect 192.168.1.106:5555”. ¬†You can type “adb devices” afterwards to verify that your device is successfully connected. ¬†That is all you have to do on the phone.

What to do on your computer

Go to Eclipse and click on the green play button so a drop-down list appears. ¬†Press “Run Configurations”.

Next, press “Target”. ¬†Change the radio button from “Automatic” to “Manual”. ¬†Press “Apply” then “Run”.

An Android Device Chooser window should appear and your device should be listed as a running Android device.  Select it and press OK.

Your phone should begin downloading the app and launching it as soon as it completes.  You can verify in the Console window on Eclipse that adb is running and uploading/installing the .apk on your phone.

What about debugging?

It is pretty cool that you can wirelessly push your app to your phone to test.  However, what if you can run debug mode in Eclipse while you step through the app on your phone?  Well you can through this method, and it is faster than the emulator.  It is not that much different from the method described above.

Make sure in your AndroidManifest.xml that “android:debuggable=true” is there. ¬†The easiest way to add this is to go to the “Application” tab in the manifest, and in “Application Attributes”, find “Debuggable”, set it to “true”, and then save. ¬†By default, my phone denies the app from being run in debug mode if the application did not explicitly declare themselves as debuggable in their manifest. ¬†So, make sure debuggable is set to true in your AndroidManifest!

Once you do that, just create breakpoints, and begin the debug mode.  Step through your app on your phone, and Eclipse will automatically switch to the Debug perspective when it hits a breakpoint.  This is seriously really cool.

Conclusion

I tried searching on Google to see if anyone else had written about this cool technique, but I wasn’t able to find anything so I decided to write my own how-to. ¬†I was in the process of uninstalling apps that I don’t use anymore, and when I stumbled upon adbWireless which I downloaded but never used before, I thought about this possibility. ¬†I tried it, and it worked. ¬†This is, in my opinion, better than the other two methods mentioned above. ¬†Laziness is good.

Filed under: Android,How to — Tags: , , , , , , — Jesse Chen @ 8:20 PM

About

Jesse is a software engineer at Facebook, who just graduated from UC Berkeley. Passionate about mobile technology and entrepreneurship, he started his own blog as a home for his tutorials, projects, and random thoughts. Follow him on Facebook to stay updated on his latest tutorials and projects.