本课程将会教你:

  1. 用Eclipse创建一个工程
  2. 用命令行工具创建一个工程

一个Android工程包了所有文件,这些文件组成你的Android App源代码。通过使用一组默认的项目目录和文件,利用Android SDK工具可以很容易地创建一个新的Android项目。本课将介绍如何使用Eclipse(通过ADT插件)或在命令行中使用SDK工具来创建一个新的项目。

注意:你应该已经安装了Android SDK,而且如果你使用Eclipse,你也应该安装了ADT插件(21.0.0或更高版本)。如果你没有这些,在你开始这节课前请按照Android SDK安装指南去安装。


用Eclipse创建工程

  1. 点击工具栏中的New .
  2. 在弹出来的窗体中,, 打开Android文件夹, 选择Android Application Project, 然后点击Next
  3. 填写弹出来的表格:
    • Application Name 用户看到的app名字. 在本工程中, 使用 "My First App."

    • Project Name 你的工程目录和Eclipse中可见的名字。
    • Package Name你的应用程序包的命名空间(和Java编程语言包使用同样的规则)。你的包的名称必须在安装Android系统上所有的软件包中是独一无二的。出于这个原因,通常最好的名字是,以你的组织或出版商的实体的反向域名开始。对于这个项目,你可以使用一些像“com.example.myfirstapp”的名字。但是,如果你使用“com.example“命名空间,你将无法在Google Play 发布你的应用程序。
    • Minimum Required SDK你的应用程序支持的最低版本的Android系统,表示使用API 的等级。为了支持尽可能多的设备,你应该设置为最低的版本,允许你的应用程序提供其核心功能设置。如果你的应用程序的任何特征只有在最新版本的Android是可能的,它不是对软件的核心功能的关键,在支持它的版本运行时(如在支持不同平台版本的讨论)再启用该功能。让这个设置为默认值。
    • Target SDK它指示你测试你的app所用的的Android SDK的最高版本(也使用API级别)。随着Android版本的更新,你应该在新版本中测你的应用程序,并且更新此值匹配为最新的API级别,以利用新平台的特点。
    • Compile With你编译你的应用程序的平台版本。默认情况下,这将使用Android SDK中的最新版本。(这应该是Android 4.1或更高;如果你没有这样的一个版本,您必须安装一个使用SDK 管理工具来安装)。你仍然可以编译你的应用程序来支持的旧版本,但设置生成目标的为最新版本,允许您启用新的功能和优化你的app,使得更多用户在新设备上体验你的app。
    • Theme指定你的app的Android UI风格. 你可以不管他。

    填完上述内容,点击Next.

  4. 在下一个屏幕中,配置工程,保留默认值,点击Next.
  5. 下一个屏幕中,可以帮助你的app创建一个启动标识。您可以通过不同的方法自定义图标,这个工具将为所有尺寸的屏幕生成图标。在你发布你的应用程序前,你应该确保你的图标的风格符合图像设计指南定义的规格。完成点击Next.
  6. 现在你可以选择从哪个开始创建你的应用程序的活动模板.对于这个项目,选择空白活动模板并单击Next.
  7. 让所有的活动模板的详细信息保留默认值,然后点击Finish.

你的Android项目已经建立,并且生成了一些默认的文件,你可以编译你的应用程序了。请继续看下一课。

用命令行工具创建工程

If you're not using the Eclipse IDE with the ADT plugin, you can instead create your projectusing the SDK tools from a command line:

  1. Change directories into the Android SDK’s tools/ path.
  2. Execute:
    android list targets

    This prints a list of the available Android platforms that you’ve downloaded for your SDK. Findthe platform against which you want to compile your app. Make a note of the target id. Werecommend that you select the highest version possible. You can still build your app tosupport older versions, but setting the build target to the latest version allows you to optimizeyour app for the latest devices.

    If you don't see any targets listed, you need toinstall some using the Android SDKManager tool. SeeAdding Platforms and Packages.

  3. Execute:
    android create project --target <target-id> --name MyFirstApp \--path <path-to-workspace>/MyFirstApp --activity MainActivity \--package com.example.myfirstapp

    Replace <target-id> with an id from the list of targets (from the previous step)and replace<path-to-workspace> with the location in which you want to save your Androidprojects.

Your Android project is now set up with several default configurations and you’re ready to beginbuilding the app. Continue to thenext lesson.

Tip: Add the platform-tools/ as well as thetools/ directory to yourPATH environment variable.

更多相关文章

  1. Android(安卓)应用程序
  2. android studio生成aar包并在其他工程引用aar包
  3. Android(安卓)Manifest.xml里内容介绍
  4. android 以编码的方式列出来当前app所有的窗口
  5. (二)第一个Android程序 HelloWorld
  6. 将Unity3D游戏移植到Android平台上
  7. Android(安卓)-- 工程目录解释
  8. 如何从python代码中直接访问Android的Service
  9. android面试

随机推荐

  1. 应用基础
  2. android小问题-去除状态栏下的阴影
  3. [翻译]Android单手指缩放-第二部分(Androi
  4. Android免Root权限Hook系统函数修改程序
  5. Android(安卓)缓存
  6. android面试题总结加强再加强版(四)
  7. 让最新的 Android(安卓)Q Beta 3 强制重
  8. android动画深入解析--仿58底部导航的ite
  9. Android(安卓)表格控件-动态实现表格效果
  10. React Native之Image组件使用时Android和