Setting Up Android Studio
You want to develop your Android applications using Android Studio, so a concise guide to setting up that IDE is useful.
The use of the Android Studio IDE is recommended by Google for developing Android apps.
Configuring the IDE is not a single shot install; several stages need to be completed. This recipe provides details on those stages.
The Android Studio Integrated Development Environment (IDE) is provided for free by Google to develop applications (Apps). Studio comes with the Android Software Development Kit (SDK) which provides essential programs to develop Android software. To set-up a development system you will need to download and run the installer for:
- Java Standard Edition Development Kit
- Android Studio
Install the JDK (Java Development Kit)
Go to the Java download page at:
Select the Java Download icon to access the JDK downloads:
The list of JDK downloads will be shown. Click the Accept License Agreement radio button, otherwise you cannot download the JDK. Download and run the file jdk-XuYY-windows-x64.exe (or jdk-XuYY-windows-i586.exe for 32 bit Windows), were XuYY is the current version. Accept any security warnings that appear but only if you are downloading from the official Java download web page. When the download has completed and is run you will need to go through the install screens clicking Next until the JDK installer has finished. You should not need to change any options presented. When the JDK installer has completed click the Finish button. A product registration web page may load, this can be closed or you can choose to register your installation.
Install Android Studio
The Android Studio download page is at: http://developer.android.com/sdk/index.html
The Android Studio install file is very large, over 1GB, a broadband Internet connection is recommended. The installation process can take some time as the installer will download additional files. Click the Download Android Studio For Windows button, accept the terms and conditions and begin the download by clicking a second Download Android Studio For Windows button. Run the android-studio-bundle-X.X-windows.exe where X.X is Studio's build number (this may not match the displayed version number, e.g. Android Studio 2.0 has a build number of 143.2739321). Accept the Windows User Account Control dialog.
On some versions of Windows 64 bit the installer requires the JAVA_HOME environment variable to be set. Use Control Panel to access System settings and open the Advanced systems settings. On the System Properties dialog the Advanced tab should be visible, click the Environment Variables button to add a new JAVA_HOME System variable, set to the path of the Java JDK (e.g. C:\Program Files\Java\jdk1.8.0, enter the correct path for your system).
Proceed through the installer's dialogs. The installer configures Studio, the Android SDK and downloads an initial Android Virtual Device (AVD). The default install location for the Android SDK is under the logged in user's AppData\Local directory. You may want to selected an easier to remember and shallower location (e.g. C:\AndroidSDK).
After installing Studio further configuration occurs when it is first run. Allow access through the Windows firewall. Further SDK packages will downloaded.
Whenever Studio runs it checks for updates and may display a message. Aside from updates to Studio itself the Android SDK and additional SDK packages are best updated via the Android SDK Manager program.
When the SDK Manager starts the Android packages available to download are checked. Then a list of all available packages are shown with some pre-selected for download. A Status column shows whether a package is installed or not. The Android SDK Tools have just been installed and this is reflected in the Status column.
Check each package that needs to be installed. There are multiple packages available: SDK Platform packages for each Application Programming Interface (API) level, application samples for most API levels and platforms, Google APIs, documentation, source code and Google extra packages which include:
- Android Support - Used to support later Android APIs on older devices.
- Play Services - For integrating with Google Play and Admob Ads.
- Play APK Expansion Library - Support for Apps that require more than 50MB APKs.
- Play Billing Library - Adds support for in App purchases.
- Play Licensing Library - Helps protects Apps from been illegally copied.
- USB Driver - For debugging on physical devices (or use a manufacturer's driver).
- Webdriver - Help test a website's compatibility with the Android browser.
- Intel Hardware Accelerated Execution Manager (HAXM) - To support the Intel x86 system images when using virtualization (installed by default).
- Android Auto simulator - For vehicle enabled Apps.
It is recommended to download several SDK Platform System Images to allow testing of Apps against various device configurations. The Google APIs System Images come with full Google APIs installed. It is worth noting that older computers will struggle to run the virtual device emulators for the later Android APIs, therefore use a physical device or develop with the earlier SDK Platforms on such computers. On recent PCs using an x86 system image can improve the performance of the emulator, especially with HAXM installed. If in doubt about what to download either accept the initial choices and re-run the SDK Manager to get other packages as and when required; or check all packages to download everything (the download will take some time and use a lot of disk space).
Click the install packages button. The selected packages will be shown in a list, if a package has licence terms that require accepting they are shown with a question mark. The packages can be accepted or rejected using the radio buttons. Rejected packages are marked with a red cross. Alternatively select the parent entry and click on Accept All to accept everything that is available. Click the Install button and a progress log will show the packages being installed, as well as any errors that occur. On Windows an error can occur (rarely) when the SDK Manager is unable to access or rename directories. Re-run the SDK Manager as administrator and check that any directories being accessed (usually the android-sdk directory) do not have any read only flags or files. When complete close the SDK Manager by clicking the X button in the top corner of the window.
Studio is now configured to build and debug Android Apps. See Set Up an Android Virtual Device (AVD) for App Testing to configure an Andriod Emulator; then try a Hello World App as a sanity check. Plug a physical device into the computer and use its settings to turn on USB Debugging.
Tip: For a few Windows users Studio may not start and a DLL error is displayed. Installing Microsoft Visual C++ 2010 SP1 Redistributable Package has been known to clear the error.
Set Up an Android Virtual Device (AVD) for App Testing
Keeping the Android SDK Updated