Getting started with Android Studio

When developing Cardboard apps for Android, there's tons of stuff that you need to track, including all your files and folders, Java classes and objects, and functions and variables. You need a properly organized Java program structure and valid language syntax. You need to set options and manage processes to build and debug your applications. Whew!

Thank goodness we have Android Studio, a powerful IDE (integrated development environment). It's built on top of IntelliJ IDEA by JetBrains, a popular intelligent Java development suite of tools.

It's intelligent because it actually gives you relevant suggestions as you write your code (Ctrl + Space), helps navigate between related references and files (Ctrl + B, Alt + F7) as well as automates refactor operations, such as renaming a class or method (Alt + Enter). In some ways, it may know what you're trying to do, even if you don't. How smart is that?

Installing Android Studio

If you don't already have Android Studio installed on your development machine, what are you waiting for? Head on over to the Android developers page (http://developer.android.com/develop/index.html) and download it to your system. It's available for Windows, Mac OS X, or Linux. You can install the full Android Studio package and not just the SDK tools. Then, obediently follow the installation instructions.

The Android Studio user interface

There's a lot to Android Studio. In most cases, we'll just explain with the help of examples as we go along. But let's take a little time to review a few features, especially the ones that are relevant to Cardboard development. Just make sure that you read the documentation available at the Android developer tools page if needed (http://developer.android.com/tools/studio/index.html).

For a beginner, the Android Studio user interface can seem daunting. And the default interface is only the beginning; editor themes and layouts can be customized to your liking. Worse, it has a tendency to change with new releases, so tutorials can seem out of date. While this can make it challenging for you to find what you need on a particular occasion, the underlying functionality does not change a whole lot. An Android app is an Android app is an Android app, in most cases. We used Android Studio 2.1 for Windows for this book (although some screen captures are from an earlier version, the interface is essentially identical).

Note

While using Android Studio, you may get notifications of the new updates available. We recommend that you do not upgrade in the middle of a project, unless you know that you really need the new improvements. Even so, make sure that you have backups if compatibility issues are introduced.

Let's take a brief tour of the Android Studio window, as shown in the following screenshot:

The Android Studio user interface

The menus of Android Studio are:

  • At the top is the main menu bar (#1) with a drop-down menu and pull out menus for just about all the features available.
  • Under the menu bar is a convenient main toolbar (#2) with shortcuts to common functions. Hovering over an icon shows a tooltip hint of what it does.
  • Under the toolbar is the main editor pane (#3). When no file is open, it says No files are open. The main editor panes are tabbed along the top when multiple files are open.
  • The hierarchy navigator pane is on the left-hand side (#4).
  • The hierarchy navigator pane has tabs along the left-hand side (vertical tabs, #5) to select between the various views of your project.

    Note

    Notice the select menu on the top left-hand side of the hierarchy pane. In the preceding screenshot, it is set to Android, which just shows the Android-specific files. There are other views that might also be useful, such as Project, which shows all the files and subdirectories under your project root directory, as mentioned earlier.

  • Along the bottom is an additional tool bar (#6) used to choose other dynamic tools you might need, including a Terminal window, build messages, debugging information, and even a to-do list. Perhaps the most important one is the Android Monitor logcat tab that provides a window to the Android logging system to collect and view the system debug output.

    Note

    It will be helpful for you to pay attention to the Debuggable Application drop-down menu, Log Level and other filters within logcat in order to filter out the "log spam" that will make it hard for you to find the output that you are looking for. Also, note that even on a high-end computer with a fast CPU, this log view can slow down Android Studio to a crawl. It is recommended that you hide this view when not in use, especially if you have multiple instances of Android Studio open.

  • Controls in the corners of each pane generally pertain to managing the IDE panes themselves.

It can be fun to poke around and browse all the different things Android Studio provides. To learn more, click on the Help | Help Topics menu items (or the ? icon on the toolbar) to open the IntelliJ IDEA help documentation (https://www.jetbrains.com/idea/help/intellij-idea.html).

Keep in mind that Android Studio is built on top of the IntelliJ IDE, which can be used for more than just the Android development. So, there's a lot here; some of which you'll never use; others you'll need but might have to hunt for.

Tip

Here's a bit of advice: with great power comes great responsibility (where have I heard this before?). Actually, with so many user interface things, a little tunnel vision will come in handy (yeah, I just made that one up). Focus on the ones you need to use when you need to use them, and don't sweat the other details.

Before we move on, let's take a glance at the main menu bar. It looks like the following screenshot:

The Android Studio user interface

Reading from left to right, the menu items are organized somewhat parallel to your application development process itself: create, edit, refactor, build, debug, and manage.

  • File: These are project files and settings
  • Edit: This includes the cut, copy, paste, and macros options, and so on
  • View: This allows us to view windows, toolbars, and UI modes
  • Navigate: This refers to content-based navigation between files
  • Code: These are code editing shortcuts
  • Analyze: This is used to inspect and analyze code for errors and inefficiencies
  • Refactor: This is used to edit code across semantically related files
  • Build: This builds the project
  • Run: This is used to run and debug
  • Tools: This is an interface with external and third-party tools
  • VCS: The refers to version-control (that is, git) commands
  • Window: This manages the IDE user interface
  • Help: This includes documentation and help links

There now, was that so scary?

If you haven't already, you might want to try and build the Cardboard Android demo app available from the Google Developers website's Android SDK Getting Started page (refer to https://developers.google.com/cardboard/android/get-started).

At the time of writing this book, the demo app is called Treasure Hunt, and there are instructions on how to clone the project from its GitHub repository. Just clone it, open it in Android Studio, then click on the green play button to build it, and run it. The rest of the Getting Started page walks you through the code that explains the key elements.

Cool! In the next chapter, we will start and rebuild pretty much the same project but from scratch.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset