My rm -rf moment

Yes, it did happen, and no, I am not stupid enough to execute rm -rf *. It was a bit more convoluted than that. I was trying to prepare a customized SD card image for the Android emulator. The fastest way to do that was to mount the SD card on my GNU/Linux machine and modify the files. The files on the SD card have root as the owner. Therefore, the easiest way to maintain a clean state was to make all modifications using sudo. My script included a command rm -r ${base_dir}/${old_file}. While executing the script, due to an error, both the variables were not set. It took me a few hours to recover; I never committed the broken script, so, I did not harm anyone else. But since then, my bash scripts have always included set -o nounset.

Android command-line: gradle and testing

For android projects, some engineers use Android Studio (new), some use Eclipse with ADT (old), few like me still savor command line, this blog post is about handling (building, installing and testing) android projects from command line.

  1. To create android project
  2. After changing to directory test_android_app (cd test_android_app), fix a bug

  3. Some useful gradle commands
  4. The code will be in src directory, eg. for the Main activity, code is in src/main/java/net/ashishb/TestAndroidApp/ and test is in src/androidTest/java/net/ashishb/TestAndroidApp/
  5. For testing, modify the Main class and add square method,

    And in MainTest
  6. Modify build.gradle to add a testing config

  7. Run the test(s)
  8. Complete code can be seen at

Android, Gradle and compile-time only dependencies

Android plugin for Gradle does not support Java-style compile time only dependencies.

After spending a few hours on trying to build android app targeted for Amazon SDK (without using Amazon’s Android specific plugin but just their jar stubs for maps, ADM and Home widget), I finally found that the one way to support compile-time dependencies is following.

For application project

For the library project