Android environment build and create Android app by command line mode

Source: Internet
Author: User

Experiment Create Android apps from the command line

This article is primarily to build an Android environment, then create an Android app from the command line , compile and package with Ant, and deploy with adb .

(This article is mainly to prevent the next time to build the Android environment to forget the steps ...) )

Experimental steps:

    1. Setting up an experimental environment

Download ANT

first download apache ant from http://ant.apache.org/bindownload.cgi

If you enter this page

Access http://ant.apache.org/bindownload.cgi , select a version ( e.g. 1.10.1) Download, window The platform should be downloaded Zip format of the package. After downloading the direct decompression can (if you choose to extract to C:\Anroid, the direct ant directory is:C:\Android\ apache-ant-1.10.1)

The version I chose to download here is 1.10.2, which is the first installation package

download and unzip to C:\Android, you can see the contents of the ant package as follows:

Download SDK

also need to download is the Android Software Development Kit, available from http://developer.android.com/index.html

after downloading, unzip, you can see AVD manager.exe,sdk Maneger.exe(SDK Manager) Two program files, running the SDK Manager.exe can install a variety of Android tools, such as the following parts of the folder is installed after the get.

    1. Configuring Environment variables

Configure by the following table:

Variable name

Variable Value

Note

Java_home

C:\Program files\java\jdk1.8.0_40

If configured, you do not have to change

Ant_home

E:\Android\apache-ant-1.8.2

New variable

Android_home

E:\Android\android-sdk-windows

New variable

CLASSPATH

$JAVA _home\jre/lib; $JAVA _home\lib; $JAVA _home/lib/tools.jar

If configured, you do not have to change

Path

;%ant_home%\bin;%java_home%\bin;%android_home%\tools;

%android_home%\platform-tools;

There are already variables, adding the value of the variable to the back of the original content

Note here: The environment variables must be well-equipped, or run the program later when the error

①java_home : (this variable is usually fitted after installing the JDK )

②ant_home: Is ANT 's storage path

③android_home: Storage directory for the SDK

④classpath: Note here to add in the following table

⑤path: Add android_home,java_home , etc.

    1. Establish an Droid Engineering

assuming the project is named "Hellocommandline", enter the following command in CMD (note that the bold font part is replaced by your own):

Android Create Project-n hellocommandline -K edu.hrbeu.HelloCommandline -a hellocommandline -T 1 -P g:\Android\workplace\HelloCommandline

where - n Specifies the name of the project to be created

-K The package name of the specified project

-A specifies the name of the Activity to be created

- T Specify the platform that the project targets for Android

- P Specify a save path for this item

//

Here's The Hellocommandline folder is automatically generated, and if the folder already exists, it must be empty, otherwise prompt

//

Enter the above command on the command line to create Android Project

For example, in hellocommandline folder created under E-Drive

Real

After you run the command line, you can see the information to create each file:

after the comparison is created files generated within the Hellocommandline

    1. Use Ant compiling and packaging projects

Use CMD, in the project root directory, enter ant debug, after the command runs,Apache ant generates a packaged file in the bin Directory hellocommandline-debug.apk and hellocommandline-debug-unaligned.apk

first go to E:\Android\workspaces\HelloCommandline, which is the root directory of hellocommandline , then run the ant bug Command

As shown, a series of files, such as the Build.xml file , have been created successfully

Enter Hellocommandline 's bin directory, you can see that the hellocommandline-debug.apk and hellocommandline-debug-unaligned.apk two files

5. Upload the program to the simulator

(1) use avd Manager to start an avd;

Double-click the AVD Manager.exe in the SDK directory

Start one of the emulators

(2) in CMD , enter the directory,

Enter the command adb install hellocommandline-debug.apkto complete the process of uploading the APK program to the simulator. Observe the command-line interface prompting information and the emulator's interface changes. If the upload is successful, you can run it in the emulator.

go to the bin directory of the project

ADB is not an internal or external command when it first runs because the previous environment variable was not configured successfully, reconfigure and restart the emulator

After successful operation, the interface of the Android virtual device will appear directly.

At this point, the Android environment configuration and knowledge of creating Android apps via command line is over.

Android environment build and create Android app by command line mode

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.