Expert Android Studio. Dundar Onur

Чтение книги онлайн.

Читать онлайн книгу Expert Android Studio - Dundar Onur страница 7

Expert Android Studio - Dundar Onur

Скачать книгу

Manager button in Android Studio screen." target="_blank" rel="nofollow" href="#i000007600000.jpg"/>

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 Studio window.

Figure 2.8 Project view on Android Studio

If you prefer to list resources similar to the way they are hosted in the file system, click the Android list on the top left and a menu with different options will open. Choose Project, and Android Studio will group your project resources as they appear in the file system, as shown in Figure 2.9.

Traditional project view window.

Figure 2.9 Traditional project view

      Let's examine this view to gain a better understanding of Android Studio project structure. Every project has a few hidden folders, which you might not be able to navigate with your file manager.

      Typically, an Android project has three hidden folders, as listed at the top left of Figure 2.9. The hidden folders are:

      • .idea folder– This folder keeps IntelliJ-specific project metadata and settings not necessarily shared with source control systems (so not shared to someone else).

      • .gradle folder– This folder keeps Gradle-related bin files. This folder's contents are not subject to change unless you change the project's Gradle version.

      • .google folder– This folder includes sample packing files from Google.

      NOTE

      Typically, users should not directly edit any file in the hidden folders. Let the IDE deal with them.

      Next is the application folder. The name of this folder can change depending on your application name and preferences. However, you can easily recognize the folder because it has a small device symbol on the lower right of the folder icon. This type of folder holds the source code, application files, and configuration.

      There can be more than one Application folder in your project depending on its size and architecture. In this chapter we will assume there's one named “app,” but will dig into different combinations in later chapters.

      Expand the app folder by clicking the triangle to the left of the folder name. If you have developed Android applications before, the contents should be familiar to you. If not, the following pages give detailed information.

      The project folders are:

      • build folder– This folder might be the least important of all because, as a developer, you won't need to deal with or edit anything inside it. The Gradle build system will be triggered to build your source files by the IDE and produce the output into this folder.

      • src/main folder– This folder might be the most important folder because it hosts all your source code except for tests. If you expand the src folder, you

Скачать книгу