Friday, January 27, 2012

Rescuing disk MBR with Ubuntu

I was very pleasantly surprised with a tool called Boot-Repair provided by Ubuntu. If you end up hosing up the MBR of your drive, Boot-Repair will come to the rescue:

http://help.ubuntu.com/community/Boot-Repair

Will re-install grub for you on your Linux partition. It really saved me hours of researching and troubleshooting. Thank you Ubuntu developers and Canonical for making such great contributions to open source.

Saturday, January 21, 2012

?????? in Devices on Eclipse

Attaching new devices on your Ubuntu Linux can be annoying because the system does not give you permission to access. Simply put, you have to let udev know about special permission to your device.

First we have to grab vendor id from lsusb or android developers site.

lsusb method:
Run

lsusb

look for a your device (phone manufacturer), the listing looks like formatted like this vendorId:modelId, i.e.:
...
Bus 001 Device 006: ID 22b8:7090 Motorola PCS
...

now make sure permission get set on every usb plug event:
add/create new to /etc/udev/rules.d/51-android.rules:

SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0666", GROUP="plugdev"

set the right permissions on 51-android.rules (if just created the file):

-rw-r--r-- 1 root root  213 2008-12-04 22:45 51-android.rules

or

chmod a+r 51-android.rules

Done.

Credit: Android developer site

Tuesday, January 17, 2012

Upgrade to PAE kernel on Ubuntu 11.04

In case you got some new ram installed and now your total ram is more than 4GB, upgrading your Ubuntu kernel (PAE) to support that higher memory is a breeze.

sudo apt-get install linux-generic-pae linux-headers-generic-pae


Credits: Ubuntu PAE Wiki.

Thank you Ubuntu developers and community for making your best work available for free.

Sunday, September 25, 2011

Remove app from device (fast)

This guide is a fast way to remove an apk you have been developing from the device:


  1. For easy access to the adb binary, create a folder in your home directory bin and place a symbolic link to your original adb binary.
    cd ~
      • mkdir bin
      • cd bin
ln -s ../Software/android-sdk-linux_86/platform-tools/adb adb
(if your original adb binary lives in /home/your_user_name/Software/android-sdk-linux_86)
  1. Re-login to your Ubuntu workstation and you are done.
Next time to quickly remove your app, open a terminal prompt (Ctrl+Alt+T) and type adb uninstall your.app.package.name.

Sunday, August 28, 2011

Android Logging Best Practices

You are implementing some small piece of logic, deep inside of your code's activities and a crash occurs, problem is, you have been scrolling LogCat window and you can't find your exception. Here are some best ways to stop wasting time, filtering out the useless:
  • Create a TAG with which you will be logging all the time. Saves memory and time. i.e. 
public static final String TAG = "MyApplicationTag";
or
public static final String TAG = MyActivityClass.class.getSimpleName();

...

Then in your code:
...

Log.d(TAG, "log this");


One for an entire application, one per activity. As long as it makes sense to you and you can quickly find it.

Additional tips:
  • Setup additional tabs inside of LogCat. These are very useful:
    • AndroidRuntime
    • System.err
    • MediaProvider
  • Create a utility class
public static class SuperAppLog {

public final static String TAG = SuperAppLog.class.getSimpleName();

public void error(String message) {
// .. do some app wide logging
// .. redirect to a file
// .. fire off a analytics logging request
// .. etc
}

}



That's it. If you want to get more fancy or mess around with Log levels, check out this answer or this guide.

Happy Coding!