Chapter One: Android Studio introduction [Learn Android Studio Chinese Tutorial]

Source: Internet
Author: User
Tags configuration settings



Excerpt from: http://ask.android-studio.org/?/question/789, re-organized for easy learning.



This chapter guides you through the installation and setup of the development environment, and then you can follow the examples and lessons of this book.    First, you will install the necessary components called the Java Development Kit (JDK).    Then you download and install Android Studio and the Android Software Development Kit (SDK), which are all the tools necessary to develop an Android application.  Next, we'll show you how to use the New Project Wizard to create a simple project HelloWorld.  Finally, we'll show you how to connect Android virtual devices (AVD) and Android physical devices. At the end of this chapter, you'll have everything you have to develop Android apps in Android Studio.



Installing JDK under Windows



This section applies to Windows users. If you are a Mac user, skip to the next section, "Install JDK on Mac". Android Studio is built using the Java compilation environment, so before you start using Android Studio you need to make sure that you have installed the Java SDK (JDK). If you're an experienced Android or Java developer, you probably already have a JDK installed on your PC. You can skip this section if the JDK on your PC is running version 1.6 or higher. In addition, you will download, install and configure the latest version of the JDK. You can download the JDK from the following Oracle Web site:
Www.oracle.com/technetwork/jav .... Html
After opening the Web site, click on the Java Download button, shown in 1-1.




Figure 1-1 Java Download button on Java Download interface



Download the JDK used on Windows



As shown in the next 1-2, you need to click the radio button to accept the license agreement. Then choose the JDK that fits your operating system. If you are a Windows 7 or Windows 8 system, you should click on the x64 version of the file link to the right window, as shown in 1-2. Oracle releases the updated version of the JDK frequently. The new version of the JDK is basically available when the book is printed, so download the latest version of the JDK. Then wait for the installation file to download. The file size is usually about 125MB, so the download should not take much longer.



Figure 1-2 Accept the license agreement and click on the appropriate link
Executing the JDK Wizard on Windows


Perform the JDK Wizard on Windows


Before installing the JDK, create a new folder named Java in the root directory of your C drive. The name of the folder can be arbitrary and is called Java because there are many Java-related tools to install here, including Jdk,android Studio and the Android SDK. Installing Android Studio-related tools in the C:\Java directory will ensure that your development environment is more organized.
Locate the location where your browser downloads the installation files and then double-click Execute. When the installation starts, you will see the Installation wizard, shown in 1-3. Under Windows systems, the JDK is installed by default in the C:\Program files\java\ directory. To change the location of the installation directory, click the Make button. We recommend installing the JDK Word C:\Java directory because it is easy to remember because its path name does not contain spaces. As shown in 1-4.




Figure 1-3 JDK Installation wizard window




figure 1-4 Selecting the JDK installation directory
Remember where the JDK is installed. Follow the prompts until the installation is complete. If prompted to install the Java Runtime Environment (JRE), select the same directory as the JDK installation location.


Configuring environmental Variables on Windowswindows Configuring environment variables


This section will show you how to configure Windows for Android Studio to find the JDK. To run Windows on your computer, press and hold the Windows key and pause key to open the System window. Click the Advanced system Settings option, shown in 1-5.




Figure 1-5 Windows system window

Click on the "Environment variables" button, as shown in 1-6. 1-7, locate the Java_home entry in the list of system variables below. If Java_home does not exist, click New to create, otherwise, click Edit.




Figure 1-6 System Properties




Figure 1-7 Environment variables
Click Add or edit to display a dialog box as shown in 1-8. Be sure to enter Java_home in the variable name. Then, in the variable value, enter the location of the JDK you just installed (minus the trailing slash), as shown in 1-4. then click OK.




Figure 1-8 Editing the Java_home environment variable

Similarly, just as you edit the java_home environment variable, you need to edit the PATH environment variable. As shown in 1-9. Move your cursor to the last side of the variable value and enter the following path:

;%JAVA_HOME%\bin 



Figure 1-9 Editing the PATH environment variable

Then click OK, OK, OK, save these changes and exit the system properties.

To test the success of the new JDK installation, click the Start button, enter cmd, and then enter to open the command-line window. Enter the following command in the Command Line window and press ENTER:

java -version

If you have the information shown in 1-10, congratulations, you have successfully installed the JDK.




Figure 1-10 Confirming the successful JDK installation


-------------------------------------------installing Android Studio installs Android Studio


Before you download Android Studio, create a root directory for the lessons in this book. We use C:\androidBook\ as the root of all courses in this book, but you can also choose or create any directory that you think is appropriate. For this reason, we simply become the curriculum root directory.
Downloading Android Studio is simple, open the following Web site with a browser:

Developer.android.com/sdk/installing/studio.html



Click on the ' Download Android Studio for your OS ' green large button, shown in 1-16. Next, tick the box that I have read and agree to the above terms and conditions. Click the ' Download Android Studio ' button again and the installation file will start downloading. The download file is executed after the download is complete.




Figure 1-16 Download Android Studio

After the Installation Wizard starts, click the Next button all the way down until you select the Component window. Tick the All Components checkbox shown in box 1-17. Then click Next. Agree to the terms and conditions again. When you reach the configuration Settings:install locations window, as shown in 1-18, select the installation location for Android Studio and Android SDK. To stay consistent, we installed Android Studio in C \ Java \ astudio \ Install the Android SDK on C \ Java \ asdk \ Next.




figure 1-17 Selecting Components




Figure 1-18 Choosing the Android Studio and SDK installation locations

Click the Next button all the way until both Android studio and Android SDK are installed. The window you end up showing should be 1-19. Tick the start Android Studio check box and click the Finish button to launch Android Studio. Make sure that the check box is selected, and then click the Finish button before Android studio launches. Note from now on, you need to start Android Studio from the desktop icon or from the Start menu.




Figure 1-19 completing Android Studio settings

When Android studio opens for the first time, the Installation wizard will look for the JDK on your system (such as the one installed earlier) and the location of the Android SDK. The setup Wizard should download everything for your Android Studio to start developing applications. Click the Finish button to close the Setup wizard.




Figure 1-20 Installation Wizard-Download components



------------------------------------------


Create your first project: HelloWorld


Once the installation wizard finishes, the Android Studio Welcome dialog will appear, as shown in 1-21. Click the start a new Android Studio project option.




Figure 1-21 Welcome to Android Studio

In the New Project Wizard (1-22), enter HelloWorld in application name and enter gerber.apress.com in company Domain. Please note that package name is the inverted company domain plus application name. Create the HelloWorld project under the root folder of the course. As mentioned earlier, if it is a Windows system, we use C:\androidBook\. In the case of a Mac or Linux system, your root directory name does not start with a letter, but rather a slash.




Figure 1-22 Configuring your new project

The Android operating system can run on a variety of platforms, including game consoles, televisions, watches, eyewear, smartphones and tablets. By default, the phone and tablet check box is selected and API-8 is selected as the lowest SDK. Agree to these settings and click on Next,1-23 as shown.




Figure 1-23 Choosing the form to run the app

Subsequent new project wizards will prompt you to choose a layout. Select the blank activity and click the Next button. Agree to the default name, 1-24 as shown, they should be as follows:

Activity Name: MainActivity
Layout Name: activity_main
Title: MainActivity
Menu Resource Name: menu_main





Figure 1-24 Selecting settings for a new file






------------------------------------


Using Android virtual Device Manager


Android Virtual Device Manager allows you to create an Android virtual device (AVDs) and then you can run the emulator on your PC. Simulation and simulation have a very important but subtle difference. Simulation means that the virtual device has only one form factor, simulating how the actual physical device works, but not for a particular operating system. The iOS development environment uses emulators, which may be a good choice for iOS with a limited number of devices on the platform.

For emulators, however, your computer leaves a piece of memory to replicate the environment on which the emulator is simulating the device. Android Studio uses the emulator, which means that Android virtual Device Manager launches a large sandbox for the Linux kernel and an entire Android stack in order to emulate an Android-based physical device environment. Although the emulator provides a more reliable environment than the emulator to test your application, it can take several minutes to start an AVD, depending on the speed of your computer. The good news is that your emulator is still active in memory and it's still responsive. However, if you have an Android phone or tablet, we recommend using a physical device to test your application instead of using the AVD. That is, we first use the Android virtual Device Manager to create an AVD, in later chapters we will want you to show how to connect your physical device if you have one.

Click on Android Virtual Device Manager icon 1-25 shown. In the first interface of the Android Virtual Device Manager wizard, click the Create a virtual device button. Select Galaxy Nexus1-26 on the next screen, then click Next. The next interface allows you to select a system image 1-27. Select the first option Lollopop (or the latest API) and the x86_64 ABI. Click Next. On the next screen, click the Finish button to verify your AVD settings. Congratulations, you've created a new AVD.




Figure 1-25 AVD icon




Figure 1-26 Selecting the Galaxy Nexus Hardware




Figure 1-27 Selecting the x86_64 system image

Note: The x86_64 version requires Intel hardware acceleration, which only works on a limited number of Intel chipsets. If you fail to install x86_64, try the armeabi-vxx version.

Tip: If you want to create a device that does not have a device defined in Android Studio, we recommend that you go to phonearena.com to find your model. There you will find technical specifications that you can use to create a new device definition. After you've created the definition for your new device, use the same steps to create a new AVD. There is an excellent third-party market for Android simulator called Genymotion. The Genymotion Simulator is free for non-commercial users and is good to use. Explaining how to set up and use Genymotion is beyond the scope of this book, but you can download the Genymotion emulator from genymotion.com.


-----------------------------------------------------Running HelloWorld on an AVD runs on the AVD HelloWorld


Run the HelloWorld application in the newly created AVD, the green Run button on the stand-alone toolbar, 1-28.




Figure 1-28 Running the button

Make sure that the Launch Emulator radio button is selected, and then select the combo box for Nexus API 21. Click ok1-29. Patiently wait a few minutes to start the AVD. Then you should be able to see the HelloWorld application running on your computer simulator. As shown in 1-30.



Figure 1-29 Selecting the device open emulator




Figure 1-30 Simulator


Run HelloWorld on your Android device


As mentioned earlier, although AVDS is useful for simulating specific devices, especially those that you do not have, it is preferable to develop applications on physical devices. If your PC does not have a USB cable to identify your Android device connection, you should install a USB driver. If your computer is able to recognize your Android device, you do not need to install a different or newer version of the USB driver as this may cause the USB connection to fail.
Note: Mac and Linux users typically do not need to download USB drivers to connect to Android devices and computers.

You can find the appropriate USB driver on the developer.android.com/tools/extras/oem-usb.html#, or use your favorite search engine to find the right USB driver for your model. Download the driver and install it on your computer. On your Android device, click Settings, and then open the developer options. Make sure that the USB debug check box is selected. Some devices, such as Samsung require a password to enable USB debugging, so you may want to use your favorite search engine to study how to turn on the USB debug switch on your device. If the introduction is not clear, some video resources on YouTube can also help you to turn on the USB debug switch for a specific device.

Most Android devices are equipped with a data cable at one end that has a USB interface on the other end with a small USB interface. Your Android device is connected to your computer via this data cable. Click the Android Device Listener button that is circled in figure 1-31. If the driver is installed correctly, you should be able to see the listed connected devices 1-32.




Figure 1-31 Android Device Listener button




Figure 1-32 Android device listener shows connected physical devices

Note: The connection between your PC and your Android device is using a service called the Android Debug Bridge (ADB). If you do not see the device, click the Terminal button in the lower left corner of the IDE and enter the following command:

adb start-server


It is likely that you still do not see the device after the ADB service restarts. Perhaps the USB driver requires a computer restart, although not likely.

Now click on the Green Run button (shown in 1-28). Select a connected Android device. In Figure 1-33, the connected device is an HTC One x smart phone. Click OK, wait a few seconds and you will see HelloWorld running on your Android device.




Figure 1-33 Selecting a device in the Android physical device list


Summary Summary


In this chapter, you install the Java SDK, or the JDK, and you also have Android studio and Android SDKs installed. You create a simple HelloWorld application with the New Project Wizard. Then you create a new Android virtual device, or an AVD. We've shown you how to install the required USB drivers. Finally, we show you how to run HelloWorld on AVD and Android physical devices. Now you have all the software you need to develop Android apps in Android Studio.

Translation: Evilsong
Home: Http://ask.android-studio.org/?/people/Evil_Song
Starter: Android Studio Chinese Community



Chapter One: Android Studio introduction [Learn Android Studio Chinese Tutorial]


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.