Android官方文档翻译 三 1.1Creating an Android Project

Creating an Android Project

创建一个Android项目

An Android project contains all the files that comprise the source code for your Android app. The Android SDK tools make it easy to start a new Android project with a set of default project directories and files.

一个Android项目包含所有的文件,这些文件包括对于你Android app所需要的源代码。
Android SDK工具让这些东西变得简单,你可以通过一系列的默认的项目目录和文件开始一个新的Android项目。

This lesson shows how to create a new project either using Eclipse (with the ADT plugin) or using the SDK tools from a command line.

这节课会向你展现如何创建一个新的项目:你可以通过使用Eclipse(装有ADT插件的),或者你在命令行中使用SDK工具。

Note: You should already have the Android SDK installed, and if you’re using Eclipse, you should also have the ADT plugin installed (version 22.6.2 or higher). If you don’t have these, follow the guide to Installing the Android SDK before you start this lesson.

注意:你应该早已经安装了Android SDK,如果你正在使用Eclipse,你还应该有ADT插件(22.6.2版本或者更高)。在你开始这节课之前,如果你没有把以上这些完成,请根据向导去安装Android SDK。

Create a Project with Eclipse

通过Eclipse创建一个项目

创建Android项目图

  1. Click New in the toolbar.

    点击工具栏中的New

  2. In the window that appears, open the Android folder, select Android Application Project, and click Next.

    在出现的window窗口中,打开Android 文件夹,选择Android Application Project,并且点击下一步

  3. Fill in the form that appears:

    填写出现的表格:

    Application Name is the app name that appears to users. For this project, use “My First App.”

    Application Name是展现给用户的app的名字。至于这个项目,我们使用“My First App”

    Project Name is the name of your project directory and the name visible in Eclipse.

    Project Name是项目目录的名字,这个名字是在Eclipse中可见的。

    Package Name is the package namespace for your app (following the same rules as packages in the Java programming language). Your package name must be unique across all packages installed on the Android system. For this reason, it’s generally best if you use a name that begins with the reverse domain name of your organization or publisher entity. For this project, you can use something like “com.example.myfirstapp.” However, you cannot publish your app on Google Play using the “com.example” namespace.

    Package Name是对于你的app的包的命名空间(规则请遵循Java程序语言的规则)。对于安装在Android系统中的所有的包名(每个包名对应于一个程序————译者注)中,你的包名必须是独一无二的。为此,通常你这样做是最好的:使用一个以你所在组织或者出版商实体的反向域名作为包名。对于现在这个程序,你可以使用诸如“com.example.myfirstapp”这样的包名。当然,你并不能在Google商店中发布以“com.example”作为包名的app程序。

    Minimum Required SDK is the lowest version of Android that your app supports, indicated using the API level. To support as many devices as possible, you should set this to the lowest version available that allows your app to provide its core feature set. If any feature of your app is possible only on newer versions of Android and it’s not critical to the app’s core feature set, you can enable the feature only when running on the versions that support it (as discussed in Supporting Different Platform Versions). Leave this set to the default value for this project.

    Minimum Required SDK是你的app可以支持的最低的Android版本,Android版本以API级别来区分。为了使你的程序尽可能支持更多的设备,你应该设置这个选项为能使你的app提供核心功能集的最低等级。如果你的app的一些功能仅仅支持在最新的Android版本上运行,并且这些功能不是应用程序的核心功能,你可以设置当运行在支持这些功能的Android版本上激活这些功能(如“Supporting Different Platform Versions”中讨论的那样)。对于这个程序你设置其为默认设置即可。

    Target SDK indicates the highest version of Android (also using the API level) with which you have tested with your application.As new versions of Android become available, you should test your app on the new version and update this value to match the latest API level in order to take advantage of new platform features.

    Target SDK表明你测试你的程序所用的Android版本的最高等级(也是使用API等级来区分)。随着Android新的版本变得可用,你应该在新的Android版本下测试你的app程序,为此,你需要更新以适用最新的API,这样你可以有效的利用新平台的特性。

    Compile With is the platform version against which you will compile your app. By default, this is set to the latest version of Android available in your SDK. (It should be Android 4.1 or greater; if you don’t have such a version available, you must install one using the SDK Manager). You can still build your app to support older versions, but setting the build target to the latest version allows you to enable new features and optimize your app for a great user experience on the latest devices.

    Compile With是你将依靠其编译你的app程序的平台版本。默认情况下,这个设置应该是你的SDK中可以使用的最新的Android版本。(你应该拥有Android 4.1或者更高;如果你没有这样一个可用的版本,你必须使用SDK Manager来安装一个)你仍然可以创建你的app支持更老的版本,但是设置构建目标为最新的版本可以让你体验到新特色并且你的app会在最新的设备上带给用户一个非常好的体验。

    Theme specifies the Android UI style to apply for your app. You can leave this alone.Click Next.

    Theme 是指定你的app的Android UI(用户界面)风格的。这些你可以留下不设置(默认即可)。点击Next。

  4. On the next screen to configure the project, leave the default selections and click Next.

    接下来的这个界面是配置项目,使用默认的选择即可,然后点击Next。

  5. The next screen can help you create a launcher icon for your app.You can customize an icon in several ways and the tool generates an icon for all screen densities. Before you publish your app, you should be sure your icon meets the specifications defined in the Iconography design guide.
    Click Next.

    接下来的这个界面帮助你创建一个你的APP的启动图标。你可以在以下几个方面中自定义一个图标,然后工具会自动帮你生成一个图标适用于所有的屏幕密度。在你发布你的APP以前,你应该确保你的图标符合定义在图解设计指南中的规格。点击Next。

  6. Now you can select an activity template from which to begin building your app.
    For this project, select BlankActivity and click Next.

    现在你可以从出现的选项中选择一个activity模板开始创建你的app项目。对于这个项目,你选择一个BlankActivity即可,然后点击Next。

  7. Leave all the details for the activity in their default state and click Finish.

    对于所有的activity详情,用默认状态设置即可,然后点击Finish。

Your Android project is now a basic “Hello World” app that contains some default files. To run the app, continue to the next lesson.

现在你的Android项目现在是一个基础的“Hello World”app了,它包括一些默认的文件。想要运行你的app,请继续下一节课程吧。

Create a Project with Command Line Tools

用命令行工具创建一个工程

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

如果你现在没有使用具有ADT插件的Eclipse IDE,你可以通过使用命令行工具来使用SDK去创建工程以代替Eclipse。

  1. Change directories into the Android SDK’s tools/ path.

    把目录切换到Android SDK tools/路径下。

  2. Execute:

    android list targets
    

    执行:

    android list targets(在cmd命令行中—–译者注)

    This prints a list of the available Android platforms that you’ve downloaded for your SDK.

    (命令行)显示出一系列你已经为你的SDK下载好的可用的Android平台。

    Find the platform against which you want to compile your app.Make a note of the target id.

    找到你想用其编译你的app的平台。把目标平台的id记下来。

    We recommend that you select the highest version possible.

    我们推荐你最好选择最新的版本。

    You can still build your app to support older versions, but setting the build target to the latest version allows you to optimize your app for the latest devices.

    你仍然可以创建支持旧版本的app,但是把编译目标设置成最新的版本可以让你优化你的app以适用最新的设备。

    If you don’t see any targets listed, you need to install some using the Android SDK Manager tool. See Adding Platforms and Packages.

    如果你看不见有任何列出的目标平台,你需要安装通过SDK Manager工具来进行安装。请看“Adding 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 with an id from the list of targets (from the previous step) and replace with the location in which you want to save your Android projects.

    把替换成目标列表中的一个id(之前的步骤说到的),把替换成你想保存你项目的本地地址。

Your Android project is now a basic “Hello World” app that contains some default files. To run the app, continue to the next lesson.

你的Android项目现在已经创建成为一个基本的“Hello World”app了,它包含一些默认的文件。想要运行你的app,请继续开始下一个课程吧。

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

提示:添加 platform-tools/ 和 tools/ 目录到你的PATH环境变量中。

Next: Running Your Application

下一节:Running Your Application

这些是我自己翻译的,如果您发现其中有严重错误,敬请指出。万分感谢!

posted @ 2015-11-20 18:27  末日没有进行曲  阅读(204)  评论(0编辑  收藏  举报