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:
- 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.
- 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.
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.
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.
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.