Installing Android Studio

Before any work can begin on developing an Android application, the first step is to configure a computer system to act as the development platform. This involves several steps consisting of installing the Android Studio Integrated Development Environment (IDE), including the Android Software Development Kit (SDK), the Kotlin plug-in, and the OpenJDK Java development environment.

This chapter will cover the steps necessary to install the requisite components for Android application development on Windows, macOS, and Linux-based systems.

Android Studio System requirements

Android application development may be performed on any of the following system types:

  • Windows 8/10/11 64-bit
  • macOS 10.14 or later running on Intel or Apple silicon
  • Chrome OS device with Intel i5 or higher
  • Linux systems with version 2.31 or later of the GNU C Library (glibc)
  • Minimum of 8GB of RAM
  • Approximately 8GB of available disk space
  • 1280 x 800 minimum screen resolution

Downloading the Android Studio package

Most of the work involved in developing applications for Android will be performed using the Android Studio environment. The content and examples in this book were created based on Android Studio Giraffe 2022.3.1 using the Android API 33 SDK (Tiramisu), which, at the time of writing, are the latest stable releases.

Android Studio is, however, subject to frequent updates, so a newer version may have been released since this book was published.

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

The latest release of Android Studio may be downloaded from the primary download page, which can be found at the following URL:

https://developer.android.com/studio/index.html

If this page provides instructions for downloading a newer version of Android Studio, there may be differences between this book and the software. A web search for “Android Studio Giraffe” should provide the option to download the older version if these differences become a problem. Alternatively, visit the following web page to find Android Studio Giraffe 2022.3.1 in the archives:

https://developer.android.com/studio/archive

Installing Android Studio

Once downloaded, the exact steps to install Android Studio differ depending on the operating system on which the installation is performed.

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

Installation on Windows

Locate the downloaded Android Studio installation executable file (named android-studio-<version>-windows. exe) in a Windows Explorer window and double-click on it to start the installation process, clicking the Yes button in the User Account Control dialog if it appears.

Once the Android Studio setup wizard appears, work through the various screens to configure the installation to meet your requirements in terms of the file system location into which Android Studio should be installed and whether or not it should be made available to other system users. When prompted to select the components to install, ensure that the Android Studio and Android Virtual Device options are all selected.

Although there are no strict rules on where Android Studio should be installed on the system, the remainder of this book will assume that the installation was performed into C:\Program Files\Android\Android Studio and that the Android SDK packages have been installed into the user’s AppData\Local\Android\sdk sub-folder. Once the options have been configured, click the Install button to begin the installation process.

On versions of Windows with a Start menu, the newly installed Android Studio can be launched from the entry added to that menu during the installation. The executable may be pinned to the taskbar for easy access by navigating to the Android Studio\bin directory, right-clicking on the studio64 executable, and selecting the Pin to Taskbar menu option (on Windows 11, this option can be found by selecting Show more options from the menu). 2.3.2 Installation on macOS

Android Studio for macOS is downloaded as a disk image (.dmg) file. Once the android-studio-<version>-mac. dmg file has been downloaded, locate it in a Finder window and double-click on it to open it, as shown in Figure 2-1:

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

Figure 2-1

To install the package, drag the Android Studio icon and drop it onto the Applications folder. The Android Studio package will then be installed into the Applications folder of the system, a process that will typically take a few seconds to complete.

To launch Android Studio, locate the executable in the Applications folder using a Finder window and double-click on it.

For future, easier access to the tool, drag the Android Studio icon from the Finder window and drop it onto the dock.

Installation on Linux

Having downloaded the Linux Android Studio package, open a terminal window, change directory to the location where Android Studio is to be installed, and execute the following command:

tar xvfz /<path to package>/android-studio-<version>-linux.tar.gzCode language: plaintext (plaintext)

Note that the Android Studio bundle will be installed into a subdirectory named android-studio. Therefore, assuming the above command was executed in /home/demo, the software packages will be unpacked into /home/demo/android-studio.

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

To launch Android Studio, open a terminal window, change directory to the android-studio/bin sub-directory, and execute the following command:

./studio.shCode language: plaintext (plaintext)

The Android Studio setup wizard

If you have previously installed an earlier version of Android Studio, the first time this new version is launched, a dialog may appear providing the option to import settings from a previous Android Studio version. If you have settings from a previous version and would like to import them into the latest installation, select the appropriate option and location. Alternatively, indicate that you do not need to import any previous settings and click the OK button to proceed.

If you are installing Android Studio for the first time, the initial dialog that appears once the setup process starts may resemble that shown in Figure 2-2 below:

Figure 2-2

If this dialog appears, click the Next button to display the Install Type screen (Figure 2-3). On this screen, select the Standard installation option before clicking Next.

Figure 2-3

On the Select UI Theme screen, select either the Darcula or Light theme based on your preferences. After making a choice, click Next, and review the options in the Verify Settings screen before proceeding to the License Agreement screen. Select each license category and enable the Accept checkbox. Finally, click the Finish button to initiate the installation.

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

After these initial setup steps have been taken, click the Finish button to display the Welcome to Android Studio screen using your chosen UI theme:

Figure 2-4

Installing additional Android SDK packages

The steps performed so far have installed the Android Studio IDE and the current set of default Android SDK packages. Before proceeding, it is worth taking some time to verify which packages are installed and to install any missing or updated packages.

This task can be performed by clicking on the More Actions link within the welcome dialog and selecting the SDK Manager option from the drop-down menu. Once invoked, the Android SDK screen of the Settings dialog will appear as shown in Figure 2-5:

Figure 2-5

Google pairs each release of Android Studio with a maximum supported Application Programming Interface (API) level of the Android SDK. In the case of Android Studio Giraffe, this is Android Tiramisu (API Level 33). This information can be confirmed using the following link:

https://developer.android.com/studio/releases#api-level-support

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

Immediately after installing Android Studio for the first time, it is likely that only the latest supported version of the Android SDK has been installed. To install older versions of the Android SDK, select the checkboxes corresponding to the versions and click the Apply button. The rest of this book assumes that the Android Tiramisu (API Level 33) SDK is installed.

Most of the examples in this book will support older versions of Android as far back as Android 8.0 (Oreo). This ensures that the apps run on a wide range of Android devices. Within the list of SDK versions, enable the checkbox next to Android 8.0 (Oreo) and click the Apply button. Click the OK button to install the SDK in the resulting confirmation dialog. Subsequent dialogs will seek the acceptance of licenses and terms before performing the installation. Click Finish once the installation is complete.

It is also possible that updates will be listed as being available for the latest SDK. To access detailed information about the packages that are ready to be updated, enable the Show Package Details option located in the lower right-hand corner of the screen. This will display information similar to that shown in Figure 2-6:

Figure 2-6

The above figure highlights the availability of an update. To install the updates, enable the checkbox to the left of the item name and click the Apply button.

In addition to the Android SDK packages, several tools are also installed for building Android applications. To view the currently installed packages and check for updates, remain within the SDK settings screen and select the SDK Tools tab as shown in Figure 2-7:

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

Figure 2-7

Within the Android SDK Tools screen, make sure that the following packages are listed as Installed in the Status column:

  • Android SDK Build-tools
  • Android Emulator
  • Android SDK Platform-tools
  • Google Play Services
  • Intel x86 Emulator Accelerator (HAXM installer)*
  • Google USB Driver (Windows only)
  • Layout Inspector image server for API 31 and 34

*Note that the Intel x86 Emulator Accelerator (HAXM installer) cannot be installed on Apple silicon-based Macs.

If any of the above packages are listed as Not Installed or requiring an update, select the checkboxes next to those packages and click the Apply button to initiate the installation process. If the HAXM emulator settings dialog appears, select the recommended memory allocation:

Figure 2-8

Once the installation is complete, review the package list and ensure that the selected packages are listed as Installed in the Status column. If any are listed as Not installed, make sure they are selected and click the Apply button again.

Installing the Android SDK Command-line Tools

Android Studio includes tools that allow some tasks to be performed from your operating system command line. To install these tools on your system, open the SDK Manager, select the SDK Tools tab, and locate the Android SDK Command-line Tools (latest) package as shown in Figure 2-9:

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

Figure 2-9

If the command-line tools package is not already installed, enable it and click Apply, followed by OK to complete the installation. When the installation completes, click Finish and close the SDK Manager dialog.

For the operating system on which you are developing to be able to find these tools, it will be necessary to add them to the system’s PATH environment variable.

Regardless of your operating system, you will need to configure the PATH environment variable to include the following paths (where <path_to_android_sdk_installation> represents the file system location into which you installed the Android SDK):

<path_to_android_sdk_installation>/sdk/cmdline-tools/latest/bin
<path_to_android_sdk_installation>/sdk/platform-toolsCode language: plaintext (plaintext)

You can identify the location of the SDK on your system by launching the SDK Manager and referring to the Android SDK Location: field located at the top of the settings panel, as highlighted in Figure 2-10:

Figure 2-10

Once the location of the SDK has been identified, the steps to add this to the PATH variable are operating system dependent:

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

Windows 8.1

  • 1. On the start screen, move the mouse to the bottom right-hand corner of the screen and select Search from the resulting menu. In the search box, enter Control Panel. When the Control Panel icon appears in the results area, click on it to launch the tool on the desktop.
  • 2. Within the Control Panel, use the Category menu to change the display to Large Icons. From the list of icons, select the one labeled System.
  • 3. In the Environment Variables dialog, locate the Path variable in the System variables list, select it, and click the Edit… button. Using the New button in the edit dialog, add two new entries to the path. For example, assuming the Android SDK was installed into C:\Users\demo\AppData\Local\Android\Sdk, the following entries would need to be added:
C:\Users\demo\AppData\Local\Android\Sdk\cmdline-tools\latest\bin
C:\Users\demo\AppData\Local\Android\Sdk\platform-toolsCode language: plaintext (plaintext)
  • 4. Click OK in each dialog box and close the system properties control panel.

Open a command prompt window by pressing Windows + R on the keyboard and entering cmd into the Run dialog. Within the Command Prompt window, enter:

echo %Path%Code language: plaintext (plaintext)

The returned path variable value should include the paths to the Android SDK platform tools folders. Verify that the platform-tools value is correct by attempting to run the adb tool as follows:

adbCode language: plaintext (plaintext)

The tool should output a list of command-line options when executed.

Similarly, check the tools path setting by attempting to run the AVD Manager command-line tool (don’t worry if the avdmanager tool reports a problem with Java – this will be addressed later):

avdmanagerCode language: plaintext (plaintext)

If a message similar to the following message appears for one or both of the commands, it is most likely that an incorrect path was appended to the Path environment variable:

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

'adb' is not recognized as an internal or external command, operable program or batch file.Code language: plaintext (plaintext)

Windows 10

Right-click on the Start menu, select Settings from the resulting menu and enter “Edit the system environment variables” into the Find a setting text field. In the System Properties dialog, click the Environment Variables… button. Follow the steps outlined for Windows 8.1 starting from step 3.

Windows 11

Right-click on the Start icon located in the taskbar and select Settings from the resulting menu. When the Settings dialog appears, scroll down the list of categories and select the “About” option. In the About screen, select Advanced system settings from the Related links section. When the System Properties window appears, click the Environment Variables… button. Follow the steps outlined for Windows 8.1 starting from step 3.

Linux

This configuration can be achieved on Linux by adding a command to the .bashrc file in your home directory (specifics may differ depending on the particular Linux distribution in use). Assuming that the Android SDK bundle package was installed into /home/demo/Android/sdk, the export line in the .bashrc file would read as follows:

export PATH=/home/demo/Android/sdk/platform-tools:/home/demo/Android/sdk/cmdlinetools/latest/bin:/home/demo/android-studio/bin:$PATHCode language: plaintext (plaintext)

Note also that the above command adds the android-studio/bin directory to the PATH variable. This will enable the studio.sh script to be executed regardless of the current directory within a terminal window.

macOS

Several techniques may be employed to modify the $PATH environment variable on macOS. Arguably the cleanest method is to add a new file in the /etc/paths.d directory containing the paths to be added to $PATH. Assuming an Android SDK installation location of /Users/demo/Library/Android/sdk, the path may be configured by creating a new file named android-sdk in the /etc/paths.d directory containing the following lines:

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

/Users/demo/Library/Android/sdk/cmdline-tools/latest/bin
/Users/demo/Library/Android/sdk/platform-tools

Note that since this is a system directory, it will be necessary to use the sudo command when creating the file. For example:

sudo vi /etc/paths.d/android-sdkCode language: plaintext (plaintext)

2.7 Android Studio memory management

Android Studio is a large and complex software application with many background processes. Although Android Studio has been criticized in the past for providing less than optimal performance, Google has made significant performance improvements in recent releases and continues to do so with each new version. These improvements include allowing the user to configure the amount of memory used by both the Android Studio IDE and the background processes used to build and run apps. This allows the software to take advantage of systems with larger amounts of RAM.

If you are running Android Studio on a system with sufficient unused RAM to increase these values (this feature is only available on 64-bit systems with 5GB or more of RAM) and find that Android Studio performance appears to be degraded, it may be worth experimenting with these memory settings. Android Studio may also notify you that performance can be increased via a dialog similar to the one shown below:

Figure 2-11

To view and modify the current memory configuration, select the File -> Settings… main menu option (Android Studio -> Settings... on macOS) and, in the resulting dialog, select Appearance & Behavior followed by the Memory Settings option listed under System Settings in the left-hand navigation panel, as illustrated in Figure 2-12 below:

Figure 2-12

When changing the memory allocation, be sure not to allocate more memory than necessary or than your system can spare without slowing down other processes.

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print

 

The IDE heap size setting adjusts the memory allocated to Android Studio and applies regardless of the currently loaded project. On the other hand, when a project is built and run from within Android Studio, several background processes (referred to as daemons) perform the task of compiling and running the app. When compiling and running large and complex projects, build time could be improved by adjusting the daemon heap settings. Unlike the IDE heap settings, these daemon settings apply only to the current project and can only be accessed when a project is open in Android Studio. To display the SDK Manager from within an open project, select the Tools -> SDK Manager… menu option from the main menu.

Updating Android Studio and the SDK

From time to time, new versions of Android Studio and the Android SDK are released. New versions of the SDK are installed using the Android SDK Manager. Android Studio will typically notify you when an update is ready to be installed.

To manually check for updates on Windows, use the Help -> Check for Updates… menu option from the Android Studio main menu (represented by the toolbar button displaying four horizontal bars) as shown in Figure 2-13:

Figure 2-13

To check for updates, on macOS, use the Android Studio -> Check for Updates… menu option.

Summary

Before beginning the development of Android-based applications, the first step is to set up a suitable development environment. This consists of the Android SDKs and Android Studio IDE (which also includes the OpenJDK development environment). This chapter covers the steps necessary to install these packages on Windows, macOS, and Linux.

 

You are reading a sample chapter from Android Studio Giraffe Essentials – Kotlin Edition.

Buy the full book now in eBook (PDF) or Print format.

The full book contains 94 chapters and over 830 pages of in-depth information.

Learn more.

Preview  Buy eBook  Buy Print