Monthly Archives: September 2015

Android Studio generate foreach loop

Begin typing foreach until autocomplete pops up.  Select “Create a for each loop”.

You’ll then get an empty for each loop that you can start filling in, first supplying the Type of each object, a variable name of your choice for that object, then hit Enter to move to the name of the variable (a Collection), then hit Enter, then supply the statements you wish to run against each item within the collection.

Pause genymotion Android Emulator on Mac

To Pause genymotion Android Emulator on Mac:

  1. Press the power button of emulator (bottom right corner)
    1. This is equivalent to executing “avd stop” within adb shell on the emulator
  2. Find the process ID number of VBoxHeadless using Activity Monitor
  3. In Terminal: kill -STOP <ID number from step 2>
    1. Your emulator is now effectively paused and uses no CPU

To Restart / Unpause Android Emulator

  1. In Terminal: kill -CONT <ID number from step 2 above>
  2. Press the power button on emulator (bottom right corner of window)
    1. Your emulator is now restarted & should operate normally


Android Studio androidTest sourceSets gradle not recognized

Android Studio (app) build.gradle sourceSets androidTest java.srcDir property may not be recognized when using the array format of this source directory property setting.


sourceSets {
    androidTest {
        java.srcDirs = ['androidTest/java']


sourceSets {
    androidTest {
        java.srcDir file('androidTest/java')

For setting up Robotium UI / Integration testing, it’s important that your androidTest source directory is recognized.

Android Fix Failed to Find Build Tools Revision

Failed to Find Build Tools Revision 2X.X.X

Android Build tools get updated often and whenever an Android project you import that is using a different Build Tools Revision than the one you’re using, you’ll see this error in Android Studio.

To fix “Failed to Find Build Tools Revision” you have 2 options:

  1. Install the missing Build Tools revision
  2. Change the Build Tools version in your ../app/build.gradle

Install missing Android Build Tools revision

Install a missing Android Build Tools revision via Tools -> Android -> SDK Manager -> SDK Tools (tab) -> Check Show Package Details (bottom right check box) -> mark the checkbox of the requested Android Build Tools version


Change the Android Build Tools Version in Build.Gradle

  1. Open app/build.gradle
  2. Find buildToolsVersion
  3. Change the version number to one you have installed (see above SDK Tools image on how to find which versions you have installed, which are marked as “Installed” or “Not Installed”)
  4. Sync Gradle.