Android Application Development and android Application Development under the command line

Source: Internet
Author: User

Android Application Development and android Application Development under the command line

This article describes how to create your first Android Application. You will learn how to create an Android project and run a debugable version of the application.

 

Before learning this article, make sure that you have installed the development environment. You need:

1. Download the android SDK.

2. Use SDKManager to download the latest SDK tools and platforms.

3. Download and install Ant.

Note: For values 1 and 2, you can also directly download and install the ADT Bundle.

 

 

Create an Android Project

An Android project contains all the files required to build an Android Application. using Android SDK Tools, you can easily create a new Android project and create default directories and files for the project.

 

This section describes how to use the SDKTools command line to create a new project.

 

Open the command line and switch to the SDK root directory/tools directory;

 

Run

Android list targets

 

 

All available platforms downloaded using the android SDK will be printed on the screen. Find the target platform you want to create the project, and record the Id of the platform. We recommend that you use the latest platform, this allows your application to support older versions of platform and allows you to optimize your application for the latest Android devices. If you do not see any available platform, you need to use SDK Manager to complete the download and installation.

 

AvailableAndroid targets:

----------

Id: 1 or "android-19"

Name: IOS 4.4

Type: Platform

API level: 19

Revision: 1

Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in

ABIs: armeabi-v7a

 

 

Run

Android create project -- target <target-id> -- name MyFirstApp \

-- Path <path-to-workspace>/MyFirstApp -- activity MainActivity \

-- Packagecom. example. myfirstapp

 

Replace <target-id> with the Id recorded in the previous step, and replace <path-to-workspace> with the path where you want to save the project, your Android project is already a basic "HelloWorld" program that contains some default files.

The directory structure is as follows:

E: \ workspace-android> tree/F MyFirstApp

List of paths of folders that work on the volume

The serial number of the volume is 00720064, 000A: 3345.

E: \ WORKSPACE \ WORKSPACE-ANDROID \ MYFIRSTAPP

│ AndroidManifest. xml

│ Ant. properties

│ Build. xml

│ Local. properties

│Proguard-project.txt

│ Project. properties

Zhu── bin

├ ── Libs

Performance── res

│ ├ ── Drawable-hdpi

│ Ic_launcher.png

│ ├ ── Drawable-ldpi

│ Ic_launcher.png

│ Mongo── drawable-mdpi

│ Ic_launcher.png

│ ├ ── Drawable-xhdpi

│ Ic_launcher.png

│ ├ ── Layout

│ Main. xml

│ └ ── Values

│ Strings. xml

└ ── Src

└ ── Com

Example-example

└ ── Myfirstapp

MainActivity. java

 

Note: Add platform-tools/and tools/to the environment variable PATH for more convenient development.

 

 

Compile and run the Androd Application

 

An Android project is created in the previous section. By default, the project contains a series of source files, allowing you to run the application immediately.

 

This section will teach you how to install and run your application on a real android device using the command line.

 

Before running an application, you must know several files and directories in the project:

 

AndroidManifest. xml

Manifest file describes the basic features of an application and defines each component.

Src/

This is a folder that stores the main source code of an application. By default, it contains an Activity class, which runs when you click the application icon to start.

Res/

Contains directories that store resource files, such:

Drawable-hdpi/

Stores image materials for HDPI screens. Similarly, other similar folders store image clips for other screens.

Layout/

Stores the files that define the user interface.

Values/

Stores other XML files, which are also a collection of all resources, such as the definition of strings and colors.

 

After compiling and running the project, the default Activity class starts and loads a layout file. The page displays "Hello World", which is nothing to be excited about, it is important that you learn how to run an Android Application before you start development.

 

If you have a real Android device, follow these steps to install and run your application on your device:

• Connect your device to your computer using a USB cable. If you are developing on a windows system, you may also need to install the corresponding USB driver of your device. For details, see the oem usb Drivers document.

• Enable USB debugging on the device.

• On most devices running Android or older versions, this option is available in Settings> Application> development options.

• In Andriod4.0 or later, this option is included in "Settings> developer options.

Note: From Android4.2, the developer options are hidden by default. To make them visible, you can go to "Settings> about mobile phones (or devices) "click" version number "seven times. Then, you can find the developer options.

• Switch the current directory to the root directory of the Andriod project through the command line to ensure that you have installed the ant tool and add the Path of the directory where the ant executable file is located to the Path environment variable. Execute:

Ant debug

• Make sure that the platform-tools/Path in the AndroidSDK has been added to the Path of the environment variable and run:

Adb install bin/MyFirstApp-debug.apk

• Find MyFirstActivity on your Android device and click open.

 

The above is the whole process of compiling and running an application on the device!

 


How does an android tablet access the command line

Enable the debugging function in menu -- set -- Application -- Development --, find an ADB driver online, and find an adb pc deamonterminal program (adb.exe and several dll ), you can use ADB to use the command line.
Or you can use the apk of the next command line online. For example, if an apk is called a Super Terminal, you can directly use the command line. However, if you do not have the root permission, many functions cannot be used.

For Android Application development problems, please refer to AVD

Android project is the android application project.
In this case, you can run the adb kill-server command in the command line, and then try the adb start-server command.

 

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.