CHAPTER 1:Android Platform 13 Android Support Library Although targeting a lower API level increases the audience of your application, it also limits the Android platform features that you can use within your application.In order to overcome this trade-off,the Android Support Library has been introduced.The Android Support Library package is a set of code libraries that provide backward-compatible versions of recent Android APls. This means that your application can benefit from an Android APl that is but can still target devicesru nnina APl l evel 4 and up.Including the Android Support Library in your An ndroid considered a best practice for Android application development. Note The Android Support Library does not cover every new APl,as some of them may require additional operating system features that are ony supported by a specific Android platform release. Each Android Support Library targets a different base API level and based on that provides a different set of backward-compatible API features.You should choose the support library flavor based on the set of features that 。4 ure Guideprovides an overview of In the next chapters,you will learn how to include the Android Support Library in your Android application. Summary This first chapter of the book covered the fundamentals of the Android platform.As indicated earlier in this chapter,you will not be directly interfacing with most of the core components that are presented in the section"Platform Architecture,"although knowing these components will make it easier for you to understand the Android framework functions that will be covered in the next few chapters. ahttp://developer.android.com/tools/support-library/features.html
CHAPTER 1: Android Platform 13 Android Support Library Although targeting a lower API level increases the audience of your application, it also limits the Android platform features that you can use within your application. In order to overcome this trade-off, the Android Support Library has been introduced. The Android Support Library package is a set of code libraries that provide backward-compatible versions of recent Android APIs. This means that your application can benefit from an Android API that is only available in API Level 19 but can still target devices running API Level 4 and up. Including the Android Support Library in your Android application is considered a best practice for Android application development. Note The Android Support Library does not cover every new API, as some of them may require additional operating system features that are only supported by a specific Android platform release. Each Android Support Library targets a different base API level and based on that provides a different set of backward-compatible API features. You should choose the support library flavor based on the set of features that you will need. The Support Library Feature Guide3 provides an overview of support library flavors from which you can choose. In the next chapters, you will learn how to include the Android Support Library in your Android application. Summary This first chapter of the book covered the fundamentals of the Android platform. As indicated earlier in this chapter, you will not be directly interfacing with most of the core components that are presented in the section “Platform Architecture,” although knowing these components will make it easier for you to understand the Android framework functions that will be covered in the next few chapters. 3http://developer.android.com/tools/support-library/features.html
Chapter Development Environment Android has a complete and advanced development environment that can run on all major operating systems Android Toolchain The Android Open Source Project(AOSP)provides a comprehensive development toolchain for application developers The AOSP builds the entire development environment by integrating carefully chosen existing open source development tools,thereby creating this comprehensive toolchain.This approach enables application developers to develop mobile applications using the tools with which they are already familiar. The Android toolchain is formed by four main components.This section discusses each of the key components. Android Software Development Kit The Android Software Development Kit(SDK)is the key component of the Android toolchain.The Android SDK provides Platform API Java Libraries An Application Packager ■Device Emulators A Bytecode Optimizer and Obfuscator
15 Chapter 2 Development Environment Android has a complete and advanced development environment that can run on all major operating systems. Android Toolchain The Android Open Source Project (AOSP) provides a comprehensive development toolchain for application developers. The AOSP builds the entire development environment by integrating carefully chosen existing open source development tools, thereby creating this comprehensive toolchain. This approach enables application developers to develop mobile applications using the tools with which they are already familiar. The Android toolchain is formed by four main components. This section discusses each of the key components. Android Software Development Kit The Android Software Development Kit (SDK) is the key component of the Android toolchain. The Android SDK provides Platform API Java Libraries An Application Packager Device Emulators A Bytecode Optimizer and Obfuscator
6 CHAPTER 2:Development Environment An Android Debug Bridge Sample Code and Tutorials Platform Documentation The Android SDK is the only required component for developing Android applications. Android Native Development Kit As indicated in Chapter 1,the Android platform relies on the Linux kernel to provide its operating system functionality.The combination of the Linux kernel and the BSD C library provides all the necessary pieces to execute platform-dependent,non-Java application code. This makes it possible to develop performance-critical portions of Android ications us sing machine c mbly.B approach is eqntlused oringor share the Android platform without rewriting it in Java. The Android Native Development Kit(NDK)provides a companion tool set for the Android SDK,designed to enable developers to build and embed native code seamlessly within Java-based applications. The Android NDK consists of cross compilers,debuggers,platform header files,and extensive documentation. Android Development Tools for Eclipse The Android Development Tools(ADT)for Eclipse were the first attempt to provide an integrated development environment(IDE)that is tailored for Android application development.As with the other components of the Android toolchain,this was achieved by providing customizations and additional features on the top of the Eclipse iDE platform. Android Studio On May 16,2013,Google announced ANDROID STUDIo',a new IDE for Android development.Android Studio is also a customized IDE experience based on INTELLIJ IDEA.Android Studio provides some additional features http://developer.android.com/sdk/installing/studio.html
16 CHAPTER 2: Development Environment An Android Debug Bridge Sample Code and Tutorials Platform Documentation The Android SDK is the only required component for developing Android applications. Android Native Development Kit As indicated in Chapter 1, the Android platform relies on the Linux kernel to provide its operating system functionality. The combination of the Linux kernel and the BSD C library provides all the necessary pieces to execute platform-dependent, non-Java application code. This makes it possible to develop performance-critical portions of Android applications using machine code generating programming languages such as C, C++, and assembly. Besides its performance advantages, this approach is frequently used for bringing existing legacy or shared code to the Android platform without rewriting it in Java. The Android Native Development Kit (NDK) provides a companion tool set for the Android SDK, designed to enable developers to build and embed native code seamlessly within Java-based applications. The Android NDK consists of cross compilers, debuggers, platform header files, and extensive documentation. Android Development Tools for Eclipse The Android Development Tools (ADT) for Eclipse were the first attempt to provide an integrated development environment (IDE) that is tailored for Android application development. As with the other components of the Android toolchain, this was achieved by providing customizations and additional features on the top of the Eclipse IDE platform. Android Studio On May 16, 2013, Google announced ANDROID STUDIO1 , a new IDE for Android development. Android Studio is also a customized IDE experience based on INTELLIJ IDEA. Android Studio provides some additional features 1http://developer.android.com/sdk/installing/studio.html
CHAPTER 2:Development Environment and improvements over EcuPSE ADT such as support for build variants and a rich user interface(Ul)layout editor.The first stable version of Android Studio.version 1.0.was released in December 2014. As Android Studio is the official Android IDE moving forward,this book uses Android Studio instead of Eclipse ADT. Setting Up the Development Environment In,you will leamn install Android Studin your ailable for all ing systems(OSs ding Wind Ma and Linux.Androi e with the Android SDK,making the environment setup simpler and easier for developers. The only prerequisites for Android Studio are the JAVA DEVELOPMENT KIT (JDK) and the JAVA RUNTIME EDmoN (JRE).The Android development toolchain supports multiple JDK and JRE flavors,such as Open JDK.IBM JDK,and merly kn as Sun JDK In order to keep the chapters of this book platform agnostic,it is assumed that the Oracle JDK will be used Although both Java versions 6 and 7 are supported by the Android toolchain,I recommend that you install Java 7 in order to be ready for upcoming Android platforms. Caution As the Android platform evolves very rapidly,the requirements and the versions of the Android development toolchain components may have changed since this book was published.You should check the Android Studio home page for the latestinformation and requirements. As the re equirements and installation instructions vary,this section covers Microsoft Windows On Microsoft Windows,both Android Studio and the Java platform come with installation packages.The installation wizards will guide you through the process of installing both applications easily
CHAPTER 2: Development Environment 17 and improvements over ECLIPSE ADT such as support for build variants and a rich user interface (UI) layout editor. The first stable version of Android Studio, version 1.0, was released in December 2014. As Android Studio is the official Android IDE moving forward, this book uses Android Studio instead of Eclipse ADT. Setting Up the Development Environment In this section, you will learn how to successfully install Android Studio on your machine. Android Studio is available for all major operating systems (OSs), including Windows, Mac OS X, and Linux. Android Studio comes prepackaged with the Android SDK, making the environment setup simpler and easier for developers. The only prerequisites for Android Studio are the JAVA DEVELOPMENT KIT (JDK) and the JAVA RUNTIME EDITION (JRE). The Android development toolchain supports multiple JDK and JRE flavors, such as Open JDK, IBM JDK, and Oracle JDK (formerly known as Sun JDK). In order to keep the chapters of this book platform agnostic, it is assumed that the Oracle JDK will be used. Although both Java versions 6 and 7 are supported by the Android toolchain, I recommend that you install Java 7 in order to be ready for upcoming Android platforms. Caution As the Android platform evolves very rapidly, the requirements and the versions of the Android development toolchain components may have changed since this book was published. You should check the Android Studio home page for the latest information and requirements. As the requirements and installation instructions vary, this section covers each OS separately. Microsoft Windows On Microsoft Windows, both Android Studio and the Java platform come with installation packages. The installation wizards will guide you through the process of installing both applications easily
18 CHAPTER 2:Development Environment Downloading and Installing JDK on Windows 1. Using your web browser,navigate to Oracle's Java download web page at www.oracle.com/ technetwork/java/javase/downloads/index.html. This page presents you with a list of download options. 2.Scroll down to the Java 7 section. 3.Click the JDK button to download the Java 7 installer application.At the time of this writing,the latest version of Java 7 is Update 71. 4.The Java 7 installation wizard will install both the JDK and the JRE.Throughout this process,you can proceed with the default values. The installation wizard will automatically perform the necessary system changes to make both the JDK and JRE available to Windows applications. including Android Studio. Downloading and Installing Android Studio on Windows 1.Using your web browser,navigate to the Android Studio download page at http://developer. android.com/sdk/installing/studio.html. 2. The web site will detect your OS,and it will show you the Android Studio download button for your OS. 3.Click the download button to download the Android Studio insta ller.At the time of this writing,the latest version of Android Studio is 1.0.1. 4.The Android Studio installation wizard will guide you through the process.You can continue with the default values throughout the installation process. Android Studio is now ready to use.In the next section,you will be building a small Android application to validate your installation. www.allitebooks.com
18 CHAPTER 2: Development Environment Downloading and Installing JDK on Windows 1. Using your web browser, navigate to Oracle’s Java download web page at www.oracle.com/ technetwork/java/javase/downloads/index.html. This page presents you with a list of download options. 2. Scroll down to the Java 7 section. 3. Click the JDK button to download the Java 7 installer application. At the time of this writing, the latest version of Java 7 is Update 71. 4. The Java 7 installation wizard will install both the JDK and the JRE. Throughout this process, you can proceed with the default values. The installation wizard will automatically perform the necessary system changes to make both the JDK and JRE available to Windows applications, including Android Studio. Downloading and Installing Android Studio on Windows 1. Using your web browser, navigate to the Android Studio download page at http://developer. android.com/sdk/installing/studio.html. 2. The web site will detect your OS, and it will show you the Android Studio download button for your OS. 3. Click the download button to download the Android Studio installer. At the time of this writing, the latest version of Android Studio is 1.0.1. 4. The Android Studio installation wizard will guide you through the process. You can continue with the default values throughout the installation process. Android Studio is now ready to use. In the next section, you will be building a small Android application to validate your installation. www.allitebooks.com