Android Command Line Development Introductory Tutorial 1

Source: Internet
Author: User

In fact, master Notepad + command line programming is very effective, whether it is the computer hardware configuration and performance problems, or for the understanding of the program internal operation mechanism, debugging and so also have a good help. But many people can understand it because of fear or dislike of using this laborious writing habit, but it is all superficial, and the post-operation is just as simple and reusable.


In fact, master Notepad + command line programming is very effective, whether it is the computer hardware configuration and performance problems, or for the understanding of the program internal operation mechanism, debugging and so also have a good help. But many people can understand it because of fear or dislike of using this laborious writing habit, but it is all superficial, and the post-operation is just as simple and reusable.

Chapter 1 AndroidEnvironment ConstructionExternal Environment

IBM,Windows XP,UBuntu10,1GRAM.

Visible Though Android has a certain need for development, simulation, and operation, but it can try to work on old-fashioned machines, just a bit slower when you start the simulator, or the rest of the past. If you do not use the simulator directly in the real world, it is even more Fine .

download variousSdk

The network has enough resources for everyone to refer to, the most important thing is Android SDK,Java SDK.

URL slightly.

I'm using it. JDK1.7,android_adt-bundle-win_x86-20140702.zip

"Need to note" After downloading from the official website, he is an empty shell, nothing, you must download according to your own needs, if you do not bother to see what is, as long as the hard disk space allows, there is nothing to download what can.

Adding environment Variables

with the Windows operating system, you must configure many environment variables, whether you are manual or automatic. Since this document is hand-developed to create Hello world, it is necessary to configure it manually to guide why.

For example:

Android_home =d:\android\android-sdks

The location of the SDK package is the directory of the Android SDK root directory, which contains tools and other folders.

For example, mine is E:\Android_adt-bundle-win_x86-20140702\sdk

Android_sdk_home =D:\Android\avd

The path to the AVD is set . However, in order to be consistent with the development tools, generally by default in the user path,

For example, mine is C:\Documents and Settings\administrator\.android

Java_home = C:\Program files\java\jdk1.7.0_05

Javase 's home directory. If you are in the installation version, you can not set it.

CLASSPATH =.; %java_home%\lib\tools.jar;%java_home%\lib\dt.jar;

       classpath environment variable. In developing the Java When you need to refer to a class written by someone else, let java sun provides us with some extra rich class packages, one is dt.jar One is tools.jar, these two jar C : \jdk1.6.0\lib jar package added to our classpath

Append the following string to the path, with a semicolon between the strings; split.

Ant_home = Setting The location of the Ant tool

Path=.;( added )%android_home%\tools;  %android_home%\platform-tools;  %java_home%\bin; %ant_home%\bin; ;%CLASSPATH%

"Note" The environment setting will not take effect until you restart your computer.

Verify that the settings are in effect

Open Windows command line, enter the following command separately, whether success is not difficult to understand.

1. >echo% android_home%

2. >java

3. >javac

4. > Ant

Chapter 2Create a firstAndoirdDemo Programusing Commands

in order to enable Android program to work, you need to send different commands, here is only a description of Android.

Incidentally, the bottom of Android is the Linux system, so Android- related things have some Linux shadow, and the habit of Windows is a little different, habits are good.

To see the commands you want to use and their parameters. Many, here in order to not be an eyesore and save space, only a few used, the other similar.

Send command

>android--help

Usage:

Android [Global options] action [action options]

Global options:

-H--help Help on a specific command. Help System

Valid actions is composed of a verb and an optional direct object:

-List:lists existing targets or virtual devices. list target or virtual device

-List avd:lists existing Android Virtual Devices. List AVD

-List target:lists existing targets. List target

-Create project:creates a new Android project. Create a project

List all the existingTarget
Android list targets

list all systems that have been downloaded after the upgrade SDK packages, they are for different target machines. It's also what you have to specify at development time.

Just try and know.

Create a project

The--create Project subcommand uses the following :

Action "Create Project":
Creates a new Android project.
Options:
-N--name Application name
-T--target SDK Target ID
Working directory for the-P--path application
-k--package Application package name
-a--activity the name of the activity created by default

Create a demo program structure framework using the following command format.

Android Create Project--target <target-id>--name myfirstapp \
--path <path-to-workspace>/myfirstapp--activity mainactivity \
--package Com.example.myfirstapp

you need to replace <target-id> for your target machine version number, and <path-to-workspace> is the directory location of the project

For example, the command I created was written like this.

> Android Create project--target 8--name myfirstapp \

--path d:/myfirstapp--activity mainactivity \

--packagecom.example.myfirstapp

in other words, I The D- packing directory created a folder Myfirstapp as my project location.

Create results

Once you have created a project using the commands above, a project framework is generated. You can send Windows commands to view:

> tree/f

The approximate location and functionality of these files is described later.

Run the project"temporary" runs on real devices

care for no or no need Android Phone Developers need, we use simulator mode to work, here is "temporary" ...

running in the emulator device

Android Virtual Device (AVD) is one of the words Android Simulator, it is very convenient for development and debugging.

Another advantage of using impersonation is that you can develop programs for many versions of the target machine by creating many emulators to install and test.


construction Project

To switch the command line to the root of your project, enter the command:

>antdebug

after execution, the last line of information is roughly as follows, OK .

Buildsuccessful

totaltime:19 seconds

here, Android will do a lot of things for you, and in order to write code at the command line, you can ignore the details. But if you look at your project directory, you'll find a few more files.

Create simulator

Send command:>android AVD

launch the AVD management interface, where you click New to create the AVD, specify platform target,SD card size, and skin (HVGA is the default ) can be.

Of course you can create multiple avd.

650) this.width=650; "border=" 0 "width=" 606 "height=" 349 "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd; "alt=" spacer.gif "/>

Figure 1. Theavd Manager showing a few virtual devices.

Publish a program to a virtual machine

Adbinstall bin/myfirstapp-debug.apk

after publishing, you can see your app's name myfirstactivity in the simulator . Click Open and you'll see how it works.

The text you see will be different from mine and will be briefly added later.

650) this.width=650; "Width=" 304 "height=" "src="/e/u261/themes/default/images/spacer.gif [style=] Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd; "alt=" Spacer.gif "/> 650) this.width=650, "width=" 292 "height=" 495 "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/E /u261/lang/zh-cn/images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

Uninstall

The uninstall process is the same as the actual phone uninstall.

Settings ,

650) this.width=650; "border=" 0 "width=" 413 "height=" 555 "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd; "alt=" spacer.gif "/>

Supplement

The project name, which is configured in strings.xml .

D:\MyFirstApp\res\values\strings.xml

<resources>

<string name= "App_name" >zuoLuoActivity</string>

</resources>

tip information: configured in main.xml .

D:\MyFirstApp\res\layout\main.xml

<textview

Android:layout_width= "Fill_parent"

android:layout_height= "Wrap_content"

Android:text= "Hello World, Zipluo"

/>


This article is from the "Shing" blog, make sure to keep this source http://cameleradmi.blog.51cto.com/9764705/1593888

Android Command Line Development Introductory Tutorial 1

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.