CHAPTER 2:Development Environment 19 Apple Mac OS X On Mac OS X,both Android Studio and the Java platform come with installer applications. Downloading and Installing JDK on Mac OS X 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 disk image.At the time of this writing,the latest version of Java 7 is Update 71. 4.Once the download is complete,double click the Java7disk image to mount it.The disk image contains the Java 7 installation application. 5.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 Mac OS X 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
CHAPTER 2: Development Environment 19 Apple Mac OS X On Mac OS X, both Android Studio and the Java platform come with installer applications. Downloading and Installing JDK on Mac OS X 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 disk image. At the time of this writing, the latest version of Java 7 is Update 71. 4. Once the download is complete, double click the Java 7 disk image to mount it. The disk image contains the Java 7 installation application. 5. 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 Mac OS X 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
20 CHAPTER 2:Development Environment 3.Click the download button to download the Android Studio disk image.At the time of this writing.the latest version of Android Studio is 1.0.1. 4. Once the download is complete,double click the Android Studio disk image. 5.Drag and drop the Android Studio icon onto the Applications icon to install Android Studio Android Studio is now ready to use.In the next section,you will be building a small Android application to validate your installation. Ubuntu Linux Compared to Microsoft Windows and Mac OS X,neither Android Studio nor the Jav s with an installat ion applica n.Both applications as compressed TAR archi ve mes through the steps that are necessary to successtully install Android Studid on Linux. 1.In order to make it easier to set up the environment, this section assumes that all Android toolchain components,including the Java 7 platform,will be installed in a new subdirectory,android,under the user's home directory.Open a Terminal window, and issue mkdir ~/android to create the new subdirectory. 2.Change the current directory to the new android directory by issuing cd~/android on the command prompt Downloading and Installing JDK on Linux 1.Using your web browser,navigate to Oracle's Java download web page at w presents you with a list of download options. 2.Scroll down to the Java 7 section
20 CHAPTER 2: Development Environment 3. Click the download button to download the Android Studio disk image. At the time of this writing, the latest version of Android Studio is 1.0.1. 4. Once the download is complete, double click the Android Studio disk image. 5. Drag and drop the Android Studio icon onto the Applications icon to install Android Studio. Android Studio is now ready to use. In the next section, you will be building a small Android application to validate your installation. Ubuntu Linux Compared to Microsoft Windows and Mac OS X, neither Android Studio nor the Java platform comes with an installation application. Both applications are available for Linux as compressed TAR archive files. This section goes through the steps that are necessary to successfully install Android Studio on Linux. 1. In order to make it easier to set up the environment, this section assumes that all Android toolchain components, including the Java 7 platform, will be installed in a new subdirectory, android, under the user’s home directory. Open a Terminal window, and issue mkdir ~/android to create the new subdirectory. 2. Change the current directory to the new android directory by issuing cd ~/android on the command prompt. Downloading and Installing JDK on Linux 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
CHAPTER 2:Development Environment 21 3.Click the JDK button to download the Java 7 compressed TAR archive file.At the time of this writing,the latest version of Java7is Update71 4.Once the download is completed,extract the Java 7 platform archive file under the ~/android subdirectory by issuing tar zxf~/Downloads/jdk 7u71-linux-i586.tar.gz.Substitute the file name based on the name of the Java 7 archive file that you have downloaded. Downloading and Installing Android Studio on Linux 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 compressed TAR archive.At the time of this writing,the latest version of Android Studio is 1.01 4.Once the download is completed.extract the Android Studio archive file unde r the~/android subdirectory by issuing tar xvf ~/Downloads/ android-studio-bundle-135.1641136-linux.tgz 5.You can now start Android Studio by issuing ~/android/android-studio/studio.sh on the command prompt
CHAPTER 2: Development Environment 21 3. Click the JDK button to download the Java 7 compressed TAR archive file. At the time of this writing, the latest version of Java 7 is Update 71. 4. Once the download is completed, extract the Java 7 platform archive file under the ~/android subdirectory by issuing tar zxf ~/Downloads/jdk- 7u71-linux-i586.tar.gz. Substitute the file name based on the name of the Java 7 archive file that you have downloaded. Downloading and Installing Android Studio on Linux 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 compressed TAR archive. At the time of this writing, the latest version of Android Studio is 1.01. 4. Once the download is completed, extract the Android Studio archive file under the ~/android subdirectory by issuing tar xvf ~/Downloads/ android-studio-bundle-135.1641136-linux.tgz. 5. You can now start Android Studio by issuing ~/android/android-studio/studio.sh on the command prompt
22 CHAPTER 2:Development Environment Hello Android Application Android Studio is now ready.In this section you will be building a Hello Android application to verify the Android toolchain installation. Creating a New Android Application Project To create a new project,complete the following steps: 1.When you start Android Studio for the first time, Quick Start dialog will be displayed as shown in Figure2-1. Android Studio Setup Welcome to Android Studio Recent Prejects Quick Start 录drig的pgn 品 OpenanisingAndroid Studio project mpot an Android code amgle Check out project from Version Control mpont Non-Android Studio project 2 Docs and How-To Figure 2-1.Android Studio Quick Star 2.Click the New Project menu item to proceed. 3.The new Android application project dialog will be displayed as shown in Figure 2-2
22 CHAPTER 2: Development Environment Hello Android Application Android Studio is now ready. In this section you will be building a Hello Android application to verify the Android toolchain installation. Creating a New Android Application Project To create a new project, complete the following steps: 1. When you start Android Studio for the first time, Quick Start dialog will be displayed as shown in Figure 2-1. Figure 2-1. Android Studio Quick Start 2. Click the New Project menu item to proceed. 3. The new Android application project dialog will be displayed as shown in Figure 2-2
CHAPTER 2:Development Environment 23 Create New Project yNew Project Android Studic Configure your new project Example Application apress.com Package name: com.apress.exampleapplication Edit Previous Ked Cancel Finish Figure 2-2.New Android application dialog 4.Set APPLICATION NAME to Hello Android 5.Set CoMPANY DoMAIN to apress.com. 6.Click the Next button to proceed. 7.As shown in Figure 2-3,on the next screen Android Studio will ask you to choose the target application programming interface(API)level for the new Android application project.Choose API Level21for Android 5.0 Lollipop
CHAPTER 2: Development Environment 23 Figure 2-2. New Android application dialog 4. Set APPLICATION NAME to Hello Android. 5. Set COMPANY DOMAIN to apress.com. 6. Click the Next button to proceed. 7. As shown in Figure 2-3, on the next screen Android Studio will ask you to choose the target application programming interface (API) level for the new Android application project. Choose API Level 21 for Android 5.0 Lollipop