Chinaunix首页 | 论坛 | 博客
  • 博客访问: 98260
  • 博文数量: 21
  • 博客积分: 451
  • 博客等级: 一等列兵
  • 技术积分: 215
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-03 20:46
个人简介

记录技术旅程

文章分类

全部博文(21)

文章存档

2014年(3)

2011年(18)

我的朋友

分类: LINUX

2011-03-17 14:06:29

Creating an Android Project

To create an Android project, you must use the android tool. When you create a new project with android, it will generate a project directory with some default application files, stub files, configuration files and a build file.

To create a new Android project, open a command-line, navigate to the tools/ directory of your SDK and run:

android create project \
--target <target_ID> \
--name <your_project_name> \
--path path/to/your/project \
--activity <your_activity_name> \
--package <your_package_namespace>

  • target is the "build target" for your application. It corresponds to an Android platform library (including any add-ons, such as Google APIs) that you would like to build your project against. To see a list of available targets and their corresponding IDs, execute: android list targets.
  • name is the name for your project. This is optional. If provided, this name will be used for your .apk filename when you build your application.
  • path is the location of your project directory. If the directory does not exist, it will be created for you.
  • activity is the name for your default Activity class. This class file will be created for you inside/src// . This will also be used for your .apk filename unless you provide a name.
  • package is the package namespace for your project, following the same rules as for packages in the Java programming language.

Here's an example:

android create project \
--target 1 \
--name MyAndroidApp \
--path ./MyAndroidAppProject \
--activity MyAndroidAppActivity \
--package com.example.myandroid

Once you've created your project, you're ready to begin development. You can move your project folder wherever you want for development, but keep in mind that you must use the Android Debug Bridge (adb) — located in the SDK platform-tools/ directory — to send your application to the emulator (discussed later). So you need access between your project solution and the platform-tools/ folder.

Tip: Add the platform-tools/ as well as the tools/ directory to your PATH environment variable.

Caution: You should refrain from moving the location of the SDK directory, because this will break the build scripts. (They will need to be manually updated to reflect the new SDK location before they will work again.)

Updating a project

If you're upgrading a project from an older version of the Android SDK or want to create a new project from existing code, use the android update project command to update the project to the new development environment. You can also use this command to revise the build target of an existing project (with the --target option) and the project name (with the --name option). The android tool will generate any files and folders (listed in the previous section) that are either missing or need to be updated, as needed for the Android project.

To update an existing Android project, open a command-line and navigate to the tools/ directory of your SDK. Now run:

android update project --name <project_name> --target <target_ID>
--path <path_to_your_project>

  • target is the "build target" for your application. It corresponds to an Android platform library (including any add-ons, such as Google APIs) that you would like to build your project against. To see a list of available targets and their corresponding IDs, execute: android list targets.
  • path is the location of your project directory.
  • name is the name for the project. This is optional—if you're not changing the project name, you don't need this.

Here's an example:

android update project --name MyApp --target 2 --path ./MyAppProject



阅读(1535) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~