Android Development QuickStart (Environment configuration)

Source: Internet
Author: User
Tags android sdk manager

Android is an exciting open-source mobile platform that is ubiquitous like a mobile phone and is supported by Google and other open-cell alliance members such as Samsung, HTC, China Mobile, Verizon, and T, so they cannot learn Otherwise you can't afford to pay for it.

It's easy to get started with Android, even without an Android phone, just a computer to install the Android SDK and device simulator.

This chapter first describes how to install all the development tools and then create a running app--android "Hello, World". If you are not a novice Android, you can quickly browse this chapter, or skip this chapter and go directly to the 2nd chapter.

1.1 Installation Tools

The Android Software Development Kit (SDK) is available for Windows, Linux, and Mac OS X, and apps developed with it can be deployed to any Android device.

For Android development, you must first install the Java, IDE, and Android SDK.

1.1.1 Java Development Kit 7.0+

First, you need to install the Java Development Kit (JDK). All Android development tools require it, and the Java language is used when writing programs. Requires JDK 7 or 8 to be installed.

Note Mac users can skip this section because Android Studio will automatically install the appropriate JDK version if you don't have one installed. However, it has been suggested that there is a problem with JDK version mismatch on Mac. If you encounter an error, refer to the troubleshooting tips for stack Overflow website 1 2.

1http://stackoverflow.com/questions/24472020

2http://stackoverflow.com/questions/16636146

Installing only the Java Runtime Environment (JRE) is not enough, and you must also install a full Java development package. It is recommended that you download the latest Java SE 8 jdk from Oracle download site 3 for updates.

3http://www.oracle.com/technetwork/java/javase/downloads

You also need to set the environment variable JAVA_HOME to point to the JDK installation location. How you set it depends on the operating system you are using. For example, in Windows 7, you can click the Start button, right-clicking Computer, select Properties, click Advanced System Settings, click the Environment Variables button, click the New button under the series variables list, and then enter Java_home in the Variable name text box. and enter the JDK installation directory in the variable value text box. Finally, click the OK button to close all the windows and save the settings.

To verify that the JDK version is correct, open a shell window (in Windows, to open the Shell window, click the Start button, enter cmd and press ENTER), and execute the following command. The following is the output I get when I execute these commands:

C:\> Java-Versionjava version"1.8.0_31"Java(Tm)SERuntime Environment (Build1.8.0_31-B13)java hotspot (tm 64-bit Span class= "Typ" >server VM  (build 25.31< Span class= "pun" >-b07, mixed Mode c:\> Echo %java_home%c:\program files \java\jdk1. 8.0_31              

You should see a similar output where the version number is 1.7 or higher.

1.1.2 Android Studio

Next, you need to install the Java Development environment (if it is not installed). It is recommended to use Android Studio because it is free and has been adopted and supported by Google developers who build Android.

Be sure to use the latest beta version or production version. Please visit Android Studio download page 4 and click the Download Android Studio button.

4http://d.android.com/sdk

Note If you don't want to use Android Studio (anyone in the world), you can also use Ides such as NetBeans and Eclipse, all with the support of the appropriate community. If you're very old-fashioned, you don't want to use the IDE at all, or you can use only command line tool 5. This book assumes that you are using Android Studio, and if not, you need to make the necessary adjustments.

5http://d.android.com/tools/help

 

What happened to eclipse?

Until recently, most Android developers still used Eclipse IDE6 and Android development Tools. In May 2013, Google launched a new development environment for Android studio--, which is based on IntelliJ idea 7, developed by JetBrains.

The biggest difference in Android studio is that it uses the Gradle compilation system. Android Studio also offers a number of new features, such as a significantly improved WYSIWYG editor, and support for generating multiple configurations using the same code. Eclipse is still supported, but most of the new developments will take place in Android studio.

6http://www.eclipse.org

7http://www.jetbrains.com/idea

After you download and install Android Studio, launch it and follow the onscreen instructions. For all settings, accept the default standard value, which is to continuously click the Next button and finally click the Finish button. Everything you need to download and install may take a few minutes, and eventually you will see the interface shown in Figure 1-1.

Figure 1-1

This means that Android Studio has been successfully installed and can start developing.

Don't forget, Android Studio is constantly evolving, so the interface you see may be slightly different from the one shown in this book. In the new version, the default file name and directory may also be different. If you encounter such differences, please adjust the operation accordingly and report to the online forum 8.

8http://pragprog.com/book/eband4

That's disgusting! Fortunately, you only have to do it once. It's time to write the first program.

1.2 Creating the first program

Android Studio comes with a number of sample programs, which are templates. Use one of the templates below to create a simple "Hello, Android" program. This can be done in just a few seconds. Please prepare the stopwatch. You ready? Let's go!

Select Start a new Android Studio project to open the New Project dialog box.

4 interfaces will appear in turn. The first interface asks for the name and storage location of the app, as shown in 1-2.

Figure 1-2

Setting the app name to Hello Android and setting the company domain name to example.org,android Studio automatically fills in other content. Click the Next button to continue execution.

The second interface prompts you to specify the applicable Android version, shown in 1-3.

Figure 1-3

Select the check box phone and Tablet, and specify the minimum SDK as the API 16:android 4.1 (Jelly Bean). This step is important, make sure that the correct version is selected. Next, click the Next button.

The third interface requires selecting the type of sample activity to add, as shown in 1-4.

Figure 1-4

Select the blank Activity with Fragment and click the Next button.

The last interface requires specifying the activity name and other information, as shown in 1-5.

Figure 1-5

Change the activity name to Helloactivity, and the other content will be filled in automatically.

In the example later in this book, in order to save time, we will indicate these new project settings in a simplified manner as follows.

    • App Name: Hello Android

    • Company Domain name: example.org

    • Size: Phone and Tablet

    • Minimum Sdk:api 16,android 4.1 (Jelly Bean)

    • Add activity: Blank activity with Fragment

    • Event Name: helloactivity

When you are finished filling in the last interface, click the Finish button. The IDE creates the specified project, which contains some default files. Next, the IDE compiles and packages it to prepare for execution.

Note in the editor that displays Fragment_hello.xml, if there is an error message about the rendering problem (Rendering problems), do not leave it, just close the window. This is a known bug in Android Studio.

The wizard has written the program, and all you need to do is try to run it. Below, first run it in the Android emulator.

1.3 running in the Android emulator

A simulator is a program that runs on one kind of hardware but can emulate another. With the Android emulator, you can create virtually any tablet, phone, and wearable virtual version on your desktop.

To run an Android program, choose Menu Run? Run ' app ', or you can click the Run button on the toolbar, as shown in 1-6.

Figure 1-6

After a while, the Choose Device dialog box appears, as shown in 1-7.

Figure 1-7

Determine that launch emulator is selected and specifies the name of the Android virtual device (AVD). Click the OK button to run the program.

The Android emulator window opens and the Android operating system starts. When you do this for the first time, this may take up to two minutes, please be patient. If the screen is locked, follow the instructions to swipe the mouse to unlock it.

Android Studio sends a copy of the program to the emulator and executes it. The app interface appears, indicating that the "Hello, Android" program is running, as shown in 1-8.

Figure 1-8

If the simulator does not appear after a few minutes, or if it looks like it stopped, it may be because your computer is not compatible with Intel hardware acceleration. To solve this problem, create a new AVD and specify the ARM processor instead of the Intel x86. For more detailed information, see section 8.1. Another solution is to use the Genymotion simulator 9.

9http://www.genymotion.com

It's so easy! Congratulations on writing your first Android program.

1.4 running on the actual device

During development, run the Android program on a physical device (such as Nexus 5). The procedure is almost the same as when running in the emulator. In devices using Android 4.2 or later, you need to enable developer mode, start app settings, select about phone or about tablet, then tap version number 7 times (this is an Easter egg provided by Android developers), and then enable USB debugging. Select developer Options? Debug "?" USB debugging ".

Install the Android USB device driver on your computer (only the Windows system needs to do this if it is not installed), and then connect the device to your computer using the USB cable that comes with your device.

It can be tricky to install the USB driver for the first time. Using Hardware Devices Page 10 provides the latest device drivers and their installation instructions. If a message box appears asking if you want to allow USB debugging (which also shows your computer's RSA key thumbprint), select the check box always let from this computer, and then click the OK button.

10http://d.android.com/tools/device.html

When you run the app later, the device appears in the Choose Device window. You can run multiple emulators and devices at the same time and select the device or emulator you want to use each time you run the app, or you can select the check box using same device for the future launches. If the device does not appear in the list, it usually means that either the USB driver is wrong or the Android version is not correct.

When the app is ready, publish it to someone else to use it. This requires a number of additional steps that will be described in detail in chapter 9th.

Shorten turnaround time

It takes a long time to start the emulator. Think of it this way: when you turn on your phone, it needs to start like any other computer system, and shutting down the emulator is like turning off the phone and removing the battery. Therefore, do not close the simulator!

You should always open the emulator window while Android Studio is running. This way, Android studio will notice that the emulator is running the next time you start the Android program, so just send the program to it to run it.

1.5 Other steps

To save time, two steps have been omitted, as described below.

1.5.1 Checking for updates

Android Studio is not very mature yet, and the revision frequency is much higher than the Android SDK. The version you download may be different from the version used in this book, and there may be some uniqueness.

For this reason, it is recommended that you automatically detect updates so that you can download and install new updates immediately. You can also check for updates manually at any time, so you can choose menu help? Check for Update.

1.5.2 Adding SDK packages

Android Studio Installer contains Android SDK and basic development tools. However, as the study progresses, you may find that additional tools are needed. To get these tools, you can run Android SDK Manager.

In Android Studio, select the menu tools? Android? SDK Manager. The manager displays a list of available components, including documents, platforms, plug-in libraries, and USB drivers, as shown in 1-9.

Figure 1-9

We recommend that you install the latest version of the following components.

    • Android SDK Tools: Software Development Kit.

    • Android SDK Platform-tools: Low-level tools such as ADB (Android Debug Bridge).

    • Android SDK build-tools: Compile tool.

    • Android 5.1 (API 22) (or later): Installs all components of the highest version.

Install the following components under category extras.

    • Android support Repository:gradle needs it.

    • Android support Library: For compatibility with older versions of Android.

    • Google Play Services: A value-added library that contains many good features.

    • Google Repository:gradle needs it.

    • Google USB Driver (Windows only): allows you to run and debug programs on your actual device.

    • Intel x86 Emulator Accelerator: Plug-in package to increase emulator speed.

After selecting all the components to install, click the Install button. The installation may take a long time to complete. When asked whether to accept the license agreement, it is important to accept all license agreements (sometimes multiple license agreements). When the message about restarting the SDK Manager appears, let the system restart.

Android Development QuickStart (Environment configuration)

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.