Android Studio

Android Studio is the new IDE (Integrated Development Environment) for Android, replacing Eclipse. See Android Studio Overview.

Install Android Studio 1.2.2
on Macintosh OS X 10.10.3 Yosemite

Installation on Microsoft Windows and Linux is similar.

  1. Make sure your Macintosh has the Java Development Kit (JDK) 6 or higher, as required by the third paragraph of Installing Android Studio. (When you install Android Studio, it actually demands JDK 7 or higher). To see what version of the Java your Mac has, go to System Preferences… and select Java. When the Java Control Panel appears, press Update. If you’re not sure whether you have Java at all, go to www.java.com and click on “Do I have Java?”.

    To download the JDK, go here and press the big square download button captioned “Java Platform (JDK) 8u45” Scroll down to “Java SE Development Kit 8u45” (not “Java SE Development Kit 8u45 Demos and Samples Downloads”) and select the .dmg file for Mac OS X x64. On my Mac, the JDK was installed into the folder
    /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home


  2. Press the big green download button to download the Android Studio .dmg file to the Downloads folder on your Macintosh. (On PC, it’s a .exe file.)

  3. Do steps 1, 2, and 3 of the instructions for Installing Android Studio. When step 3 complained “Up to date JDK was not detected”, I simply pressed Next. Under “SDK Components Setup”, I checked Android SDK and Android Virtual Device. After pressing the Finish button to finish step 3, continue with Adding SDK Packages. To add these packages, you will have to launch the SDK Manager. One way to launch it is to launch Android Studio and in the “Welcome to Android Studio” window, select
    Configure → SDK Manager.

  4. Take a peek at the files you just downloaded. For example, to see which version(s) of the Android SDK you installed, launch the Terminal application on the Macintosh and type the following commands into the Terminal window. The tilde ~ stands for the full pathname of your home directory. For the numbers 21 and 22, see What is API Level?.
    cd ~/Library/Android/sdk/platforms
    pwd
    ls -l
    drwxr-xr-x  11 myname  mygroup  374 Mar 22 21:02 android-21
    drwxr-xr-x  11 myname  mygroup  374 Mar 22 21:16 android-22
    

  5. Tell Android Studio to write your Java import statements automatically for you.
    Welcome to Android Studio → Configure → Preferences → Editor → General → Auto Import → Java
    ☑ Optimize imports on the fly
    ☑ Add unambiguous imports on the fly
    Press the Apply and OK buttons.

  6. When we installed Android Studio, we also installed many command-line tools. The names of the two directories that contain these tools should be placed into your PATH environment variable. Put the following export statement into the .bash_profile file in your home directory on your Mac. Each backslash must be the last character on its line.
    #Android SDK command-line tools
    
    export PATH=\
    ~/Library/Android/sdk/tools:\
    ~/Library/Android/sdk/platform-tools:\
    $PATH
    
    One way to find out if .bash_profile already exists, and to edit it if it does, is to launch the application TextEdit and pull down
    File → Open…
    Navigate to your home directory and type command-shift-dot to see all the files there, including the ones whose names start with a dot. After editing .bash_profile change it to a plain text file:
    Format → Make Plain Text
    and save the file. close the Terminal window (if it is open) and open a new one. See if you can run SDK tools such as adb, sqlite3, and android from the shell command line:
    echo $PATH | tr : '\n'
    which adb
    
    adb version
    Android Debug Bridge version 1.0.32
    
    adb --help
    
    sqlite3 -version
    3.8.10.2 2015-05-20 18:17:19 2ef4f3a5b1d1d0c4338f8243d40a2452cc1f7fe4
    
    sqlite3 -help
    Usage: sqlite3 [OPTIONS] FILENAME [SQL]
    etc.
    
    android --help | more
    

Install VirtualBox

We will run our apps in an Android emulator. The emulators provided by Google are too slow, so we will use the third-party emulator Genymotion. If you’re running Genymotion on a machine other than a Windows PC, it will need VirtualBox.

Go to the VirtualBox download page and download the VirtualBox binary for OS X. Double-click on the VirtualBox .dmg file in your Downloads folder.

If the link you need in the VirtualBox download page is broken, try this mirror site for the latest version of VirtualBox.

Install Genymotion

Create a Genymotion account and activate it. Get a license for the free version of Genymotion and download it. Follow the instructions for installation and getting started.

When you first launch Genymotion, click on its Settings gear and select the ADB tab.
ADB tool connection settings
• Use custom Android SDK tools
Android SDK: /Users/yourname/Library/Android/sdk       (Specify your name in place of yourname).
Press the OK button.

To create an Android virtual device, click on the Add button in the Genymotion app. The virtual device I chose to create was a Samsung Galaxy S5. After you have created the device, but before you launch it, click on the wrench icon next to the device in the Genymotion app and check the checkboxes for Android navigation bar (the black bar across the bottom of the screen) and virtual keyboard. The latter will allow an EditText object to slide a keyboard up onto the screen; see this app.

Configuration
Android system options
☑ Show Android navigation bar.
☑ Use virtual keyboard for text input.
OK

To launch the Android virtual device, select it in the Genymotion app and press the Start triangle.

If the time displayed by the virtual device is in the wrong time zone, go to the Settings app in the Android virtual device and select Date & time. Uncheck the “Automatic time zone” and select your time zone (Eastern Time, GMT −5:00). Then press the device’s Home button.

The Genymotion plugin has to be plugged into Android Studio. To see if it’s already plugged in,
Android Studio → Preferences…
In the left panel, select Plugins.
In the center panel, select Genymotion. If the right panel shows an “× Uninstall plugin” button, it means that the Genymotion plugin is already plugged in. Here are instructions for plugging it in; look for “Genymotion Plugin for Android Studio”.

If the Genymotion emulator gets stuck “Waiting for adb”, kill and re-start the adb server with the following commands in the Mac Terminal. The - is a dash. You may also have to quit and restart the emulator, and maybe also Android Studio.

adb kill-server
adb start-server

Install on Microsoft Windows

One of the students kindly supplied the following notes.

To give you some feedback on running Android Studio on Windows, when I installed Android Studio on Windows 7 I noticed a few differences:

  1. It asked me what theme I wanted to use (IntelliJ vs Dark Night or some such). I assume this is purely cosmetic.

  2. In the AndroidStudio display tab I got an error message that “this version of the rendering library is more recent than your version of Android Studio. Please update Android Studio.” But when I select “Check for Updates” it informs me that no updates can be found. (The error log refers to an org.jetbrains.android.uipreview.RenderingException error.)

  3. I got the same “compileDebugAidl” error in the Windows version off Android Studio as on my Mac, but changing the Build Tools version fixed the problem. Select app at the top of the project view. Pull down
    File → Project Structure…
    and change the Build Tools Version from 23.0.0 rc1 back to 22.0.1

  4. I tried installing GenyMotion without VirtualBox, because you’d mentioned it was only required on Macs. But when I went to run GenyMotion it complained that VirtualBox was missing and it wouldn’t run. Once I installed VirualBox (included with the GenyMotion installer), I was able to successfully run the “hello world” program using their GenyMotion emulator.

Erase everything

Suppose you wanted to to erase everything we installed above, either because you suspect you botched it and want to make a clean start, or because you’re just giving up. Launch VirtualBox, remove your virtual machines, and quit VirtualBox. Then remove the following files and directories.

  1. ~/Downloads/android-studio-ide-*.dmg
  2. ~/.android
  3. ~/Library/Android
  4. ~/AndroidStudioProjects
  5. /Applications/Android Studio.app
  6. ~/Downloads/VirtualBox-*.dmg
  7. /Applications/VirtualBox.app
  8. ~/Downloads/genymotion-*.dmg
  9. ~/.Genymobile
  10. /Applications/Genymotion.app
  11. /Applications/Genymotion Shell.app

Tutorial

Start looking at the apps we will do in class.