Expert Android Studio. Dundar Onur

Expert Android Studio - Dundar Onur


Скачать книгу
supported IDE for Android Development. Of course, you can still use ADT if you are coming from a strong Eclipse background; however, you will probably face problems that you may need to solve on your own.

      As an Eclipse committer who has written code for several Eclipse projects, I preferred to stay with ADT for a long time. However, with the announcement that Android Studio is the official IDE, “resistance is futile.”

      If you are new to Android development, it may even be easier to adapt to Android Studio because your previous Eclipse experience might not necessarily help you a lot on the IntelliJ platform.

CREATING A NEW SAMPLE PROJECT

Figure 2.1 shows the welcome screen of Android Studio, which is the first screen you will see when you launch Android Studio. From here, you can start a new project. In this chapter, you will work on a sample project, so let's open an existing project by importing the code.

Screenshot of Welcome to Android Studio window.

Figure 2.1 Welcome to Android Studio window

      1. Click the Import an Android code sample option in the list shown in Figure 2.1.

      Numerous sample projects are hosted in GitHub. Because those projects are always up-to-date and new ones are added when a new API or functionality is introduced, it is a good idea to use them as a reference template for your own projects. Plus, all those samples are under the Apache software license, which makes them available to be used freely even in commercial products.

      Because everyone loves selfies, in this example you build yet another selfie app.

      2. Scroll down to Camera and select Camera2 Basic from the list shown in Figure 2.2.

Keep the Application name and Project location that appear on the Sample Setup screen (see Figure 2.3).

Screenshot of Import Sample—Browse Samples window.

Figure 2.2 Import Sample – Browse Samples window

Screenshot of Import Sample—Sample Setup window.

Figure 2.3 Import Sample – Sample Setup window

      3. Click Finish.

      Your project will be downloaded from GitHub, and the main IDE window, which is mostly empty, will appear.

      Once you click Finish, Android Studio creates the project and switches to the main development layout. Before you figure out where to find your project files, let's take a look at Android SDK configuration in the following sidebar.

      ANDROID SDK CONFIGURATION INSIDE ANDROID STUDIO

      Android SDK can be downloaded and configured within Android Studio too with using Android Studio Preferences window. The following steps walk you through the configuration process.

      1. Click the SDK Manager icon on the right side of the top toolbar, as shown in Figure 2.4.

The Android Studio Default Preferences window opens, as shown in Figure 2.5. The window focuses on the SDK integration option, listing the installed and available SDK versions as well as showing if any of them are eligible for an update.

Display of SDK Manager button in Android Studio screen.

Figure 2.4 SDK Manager button in Android Studio

Display of Android Default Preferences for Android SDK screen.

Figure 2.5 Android Default Preferences for Android SDK window

      2. You can use the checkboxes next to installed versions and click Apply to start the installation of the desired version. As shown in Figure 2.5, a typical setup may include installed, not installed, and partially installed SDK versions.

You can also choose to start the standalone SDK Manager by clicking the Launch Standalone SDK Manager link shown at the bottom of Figure 2.5. After clicking that link, you see the detailed installation options shown in Figure 2.6.

      NOTE

      We recommend that you install and update to the latest version of Android SDK Tools and Android SDK Platform tools. The SDK version you should use mostly depends on your project requirements. As a starting point, we recommend installing the latest SDK, which is API 23, and a widely accepted version such as API 19 or 20.

Display of Android SDK Manager installation screen.

Figure 2.6 Android SDK Manager installation window

      3. Scroll down to Extras and make sure Support Repository, Support Library, Google Play Services, Google Repository, Google USB Driver (only for Windows), and Intel x86 Emulator Accelerator are selected.

      4. Once you make sure all components are selected, click the Install button and accept the license. The SDK Manager will start the download, which may take a while depending on your selections.

      NOTE

      Android SDK Manager can also be used for deleting unused SDKs and build tools.

      Alternatively, you can use the Android Studio Preferences view and select the SDK version you want to install.

      Using Different SDKs

      When the SDK installations are complete, you can start working with one of them. As long as your Android project does not make use of a feature that is introduced with a specific version of an SDK, you can easily convert your project to work with an older SDK.

      NOTE

      We recommend that you work with the latest version of the SDK to build and compile your project, but use the minSDK attribute to support the earliest supported version.

      NOTE

      We cover build and support versions of the SDK in this and following chapters.

      Android Project Structure

Everything looks great? Well, not exactly because you should probably be looking at an empty screen, as shown in Figure 2.7.

      NOTE

      We say that “you should probably be looking at an empty screen” because we want these instructions to remain version agnostic. It is possible that future updates might cause a change and your screen might not be empty.

Display of Android Studio after importing the sample project window.

Figure 2.7 Android Studio after importing the sample project

Although the initial project screen shows nothing about your project, Android Studio gives you a list of hints about how to move to the next step. For this example, press Command+1 on Mac or Alt+1 on Windows to open the project view. The project view, shown in Figure 2.8, displays all the contents of your project.

      WARNING

      If you are coming from an ADT background, be aware that Android project structure has changed dramatically with Gradle. With Android Studio, project resources are grouped by types, which does not correspond to their locations on the file system. Although this is a clever approach and is handy, it can also be tricky if you are used to the projects view from ADT.

Project view on Android <hr><noindex><a href=Скачать книгу