01_android Application Development Environment _03_ development environment building and simple Android program

Source: Internet
Author: User
Tags knowledge base

Build a development environment, create a simulator, and finally complete a simple Android app and introduce the project directory.

1 equipped with Android development environment

1.1 installing Eclipse and ADT

Download the Android SDK. The full name of the SDK is the Software Development Kit (software Development Kit), which provides some API libraries to develop Android and development tools for developing testing and debugging Android applications. ADT is an Eclipse plug-in that contains some of the toolkits needed to develop an Android application using Eclipse. Once powered by the Android development environment, you need to download Eclipse, Android Sdk,adt, and so on separately, and also need to configure the connection between its various components, now only need to visit the following URL to download: http://developer.android.com/ Sdk/index.html

For Windows platforms, just click Download the SDK ADT Bundle for Windows and, depending on the system, select 32-bit or 64-bit to download the complete ADT package.

In this downloadable ADT package, all the tools needed to develop Android apps are included. Including:

1. Eclipse with the ADT plugin installed

2. Android SDK Toolkit

3. Android Version Toolkit

4. Latest version of Android SDK

5. Android Simulator

Unzip the downloaded file, you can see the directory structure:

Where the Eclipse folder is a lite version of the Eclipse IDE, and the ADT plugin is preinstalled. Under the SDK folder is the Android SDK, which contains content related to the Android SDK, which, by default, contains only the latest version of the Android SDK in the \sdk\platforms directory. Because there are multiple versions of the Android system, if you need to develop other versions of Android apps, you also need to download other versions of the SDK, which need to be downloaded through the SDK manager.

1.2 Download Other versions of the Android SDK

The ADT package contains only the latest version of the Android SDK and needs to be downloaded through the SDK manager when other versions of the Android application need to be developed.

Run the SDK Manager, as shown:

Let's look at a few other directory structures, and the tools directory contains some standard tools for Android development. Expand see some of the necessary development tools that have been downloaded, such as:

Extras also contains some extension tools that have been downloaded for us, and here is a brief introduction to these extension tools:

    • Knowledge Base for Android support repository:android version extensions.
    • Android support Library:android backwards-compatible extension packs, because the Android version is cumbersome, extension packs can make some features of the higher version compatible with the lower version.
    • Driver for Google USB Driver:usb. This driver needs to be downloaded when debugging with a real machine.
    • Intel x86 Emulator Accelerator: Accelerator for running the emulator on Intel processors. When the current development machine uses Intel processors above i3, you can check this download to speed up the simulator startup.
    • Google Xxx: Google-based tools are some of the services offered by Google and can be downloaded if needed.

Let's take a look at what's included in the different versions of the SDK here, taking Android4.3 as an example:

For each of these items, we explain briefly:

    • SDK Platform: The jar package for the current platform.
    • Samples Simple sample code for the API for SDK:SDK.
    • Arm EABI v7a System Image: The image of the emulator is running on ARM's processor.
    • Intel x86 Atom System Image: The image of the emulator is running on Intel's processor.
    • API for Google Apis:google services.
    • Sources for Android sdk:android SDK source code.
2 Create simulator (AVD)

Android can not be developed immediately after the successful installation of the Android development environment. Because Android apps need to run on Android, Android devices are getting cheaper now, but they don't require all learners to buy an Android device to start learning, So Android provides a simulator (AVD) to emulate an Android phone, and this section explains how to create an Android emulator.

The English name of the simulator (AVD) is Android Virtual Device, which can be created through the Android emulator Manager. In Eclipse, click on Android Virtual Device Manager as labeled.

When Android Virtual Device Manager is turned on, the default is no emulator, we need to create:

Click Device definitions and choose a resolution to create the emulator. Here is the choice of 3.2 inch QVGA screen.

After selecting the screen resolution, click "Create AVD ..." to start creating a new emulator.

Creating a simulator requires a lot of properties, and here's a simple introduction:

    • AVD Name: The name of the current emulator.
    • Device: The size of the unit.
    • Target: The current version of Android, including all downloaded SDK version numbers in the current environment.
    • Cpu/abi: Select the type of CPU used by the simulator, if Intel is used and the processor above I3, you can select Intel, so the emulator will start faster.
    • Keyborad: Whether the keyboard is included.
    • Skin: Whether to use skins.
    • Back camera: If the rear camera is emulated, WEBCM0 will use the computer's camera to simulate the phone's camera.
    • Memory Options: Storage, setting the size of RAM and heap.
    • Internal Storage: Set the internal memory size, set the internal memory size of the real hard disk space, it is recommended 200.
    • SD card: Simulate an SDK card and set its size, set the SD card size to the real hard disk space, suggest 32.
    • Snapshot: Support to save the snapshot, not recommended check, there will be unknown bugs.
    • Use Host GPU: Enable GPU hardware acceleration, if the current computer is a standalone video card, it is recommended to tick.
3 simple Android Programs

Click: File→new→android Application project to create a new Android project. Such as:


4 Android Project structure analysis


The directory structure of the Helloword app that is displayed for the eclipse's package explorer. You can see that there are many different files and folders, and the files and folders in the directory are described below.

    • SRC: The Java source file that contains the project.
    • Gen: Contains the R.java files that are automatically generated by the compiler based on the resources of the project. It refers to the ability to find all the resources in the project, without the developer having to maintain them, all of which are done automatically by the compiler.
    • The Android 4.2.2:android4.2.2 jar package contains all the class libraries required for this Android application.
    • Assets: Contains all the native resources that are used in the project.
    • Bin: Contains the files that ADT produced during the build process, which packages the project into an. apk file (the installation package for Android apps). apk contains all the files required for Android to run, including. dex files, manifest files, resource files, and so on.
    • Res: This directory contains various resource files for Android projects, for example, the/layout/directory contains the interface layout files, the/values/directory holds various XML grid resource files,/drawable-xxx/directory holds some bitmap or XML resources.
    • The manifest file for the AndroidManifest.xml:Android application. You can register the four Android components in it, or you can register the permissions required for the application.

Androidmanifest.xml manifest file

Required for each Android project, it is a global profile for the entire Android project. When contacting a new project, the first thing to look at is the manifest file, the android manifest file Androidmanifest.xml can usually contain the following information:

    1. The package name and version number of the application, which corresponds to the unique identity of the app.
    2. All components included in the application (four components) need to be registered here.
    3. The app supports a compatible minimum SDK version and a target SDK version.
    4. The system permissions that the application requires.

Android for security purposes, the manifest file Androidmanifest.xml, in addition to setting up and registering the Android components for the app's basic properties, also needs to display registration for system permissions that the application may need access to. For example, the current application needs to access the network, to send text messages, to make calls, etc., which need to register the corresponding permissions in the manifest file.

For app permissions, you need to register with the <user-permission.../> element.

For example, to register access to the network for the current app:

<uses-permission android:name= "Android.permission.INTERNET"/>

For the application global permissions, register in <manifest.../>, for a component has permissions, need to be registered within the elements of the corresponding component, such as in <activity.../> can register the current activity corresponding permissions.

For the sake of system security, the Android system needs explicit permission registration for all the places that need to access the system resources, so it also provides a lot of permissions, which are defined in the Manifest.permission class in the form of constants. All permissions that are registered by the application will be prompted to know when the app is installed.

Here are some common permissions:

  • Access_network_state: Permission to allow an application to obtain network status information.
  • Access_wifi_state: Allows the application to obtain access to the WiFi network status information.
  • Battery_stats: Permission to allow the application to obtain battery status information.
  • Bluetooth: Allows the application to connect to the Bluetooth device.
  • Broadcast_sms: Allows the app to receive SMS alerts.
  • Call_phone: Permission to allow an application to make calls.
  • Camera: Allows the application to use the camera's permissions.
  • Change_network_state: Allows the application to change the network connection state permissions.
  • Change_wifi_state allows applications to change the status of the WiFi network connection.
  • Delete_cache_files: Permission to allow the application to delete cached files.
  • Delete_packages: Allows the application to uninstall the program's permissions.
  • Flashlight: Permission to allow applications to access the flash.
  • Internet: Permissions that allow applications to access the network.
  • Modify_audio_settings: Allows the application to modify the permissions of the global sound settings.
  • Read_contacts: Permission to allow the application to read contact data.
  • Read_phone_state: Permission to allow the application to read the phone status.
  • Read_phone_sms: Permission to allow an application to read text messages.
  • Read_external_storage: Allows the application to read external storage permissions.
  • REBOOT: Permission to allow an application to restart the system
  • Record_audio: Permission to allow the application to record.
  • Send_sms: Permission to allow an application to send text messages.
  • Set_orientation: Permission to allow the application to rotate the screen.
  • Set_time: Permission to allow the application to set the time.
  • Set_time_zone: Allows the application to set the time zone's permissions.
  • Set_wallpaper: Allows the application to set desktop wallpaper permissions.
  • Vibrate: Permission to allow an application to access the vibrator.
  • Write_external_storage: Allows an application to write content to external storage.

5 DDMS Commissioning Environment

After the simulator is running, it is a standalone operating system, and we cannot capture its state. So Android provides us with a debug environment for the DDMS (Dalvik debug Monitor Service), which is an Android debugging environment.

To switch to the DDMS debug environment, just click Ddms in the upper right corner of Eclipse, or open Perspective Panel select Ddms Open.

Into the DDMS debugging environment, you can see a few panels on the interface, a brief introduction to several commonly used: Devices, which shows the current running emulator process. Such as:

File Explorer, which shows the internal file structure of the system on the emulator, can import and export files on the emulator via File Explorer. Such as:

LogCat, a log output tool in which you can output some log information for Android, developers can also write run-time messages to LogCat through the log class. Such as:

Emulator control, simulator controller, which can be set to simulate some states of the simulator. such as telephone status can set the current state of the simulator;

Telephone actions can simulate a call or SMS content to the simulator;

Location controls can simulate a current position on the simulator

Once the emulator is running, it is a separate system relative to the current operating system. The current system in order to capture the information on the simulator appears to be the use of DDMS, in fact, DDMS is also with the help of Adb.exe this tool, it is located in the \sdk\platform-tools directory of the Android SDK, This directory contains some of the tools needed to develop an Android application. The full name of the ADB is the Android Debug Bridge, which translates to the Android debugging bridges that enable the current system to bridge the emulator.

01_android Application Development Environment _03_ development environment building and simple Android program

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.