Android官方入门文档[1]创建一个Android项目

Android官方入门文档[1]创建一个Android项目

 

创建一个Android项目

 

这节课教你
1.创建与Android Studio中的一个项目
2.创建使用命令行工具项目

你也应该阅读
•管理项目

Creating an Android Project

This lesson teaches you to
1.Create a Project with Android Studio
2.Create a Project with Command Line Tools

You should also read
•Managing Projects

一个Android项目包含了所有构成你的Android应用程序的源代码文件。
这节课展示了如何采用Android Studio或使用SDK工具在命令行来创建一个新的项目。
注意:您应该已经安装了Android SDK,如果你使用的是Android Studio,您还应该安装Android Studio。如果你没有这些,按照指导安装了Android SDK开始这一课前。

An Android project contains all the files that comprise the source code for your Android app.
This lesson shows how to create a new project either using Android Studio or using the SDK tools from a command line.
Note: You should already have the Android SDK installed, and if you're using Android Studio, you should also have  Android Studio installed. If you don't have these, follow the guide to Installing the Android SDK before you start this lesson.

 

创建 Android Studio项目

 

Create a Project with Android Studio

--------------------------------------------------------------------------------
1.在Android Studio,创建一个新项目:◦如果你没有一个项目打开,在欢迎屏幕上,单击新建项目。
◦如果你有一个项目打开了,从文件菜单,选择新建项目。
1.In Android Studio, create a new project: ◦If you don't have a project opened, in the Welcome screen, click  New Project.
◦If you have a project opened, from the File menu, select New Project.


图1.在配置Android  Studio中的一个新项目。
Figure 1. Configuring a new project in Android Studio.

2.在配置您的新项目,填补了字段如图1所示,然后单击下一步。
它可能会更容易,如果你使用相同的值,如图所示遵循这些课。
◦应用程序名称是出现给用户的应用程序名称。对于这个项目,使用“我的第一个应用程序。”
◦公司域提供将要附加到包名资格赛; Android Studio会记住这个限定词为你创建的每一个新项目。
◦包名称是项目(遵循相同的规则在Java编程语言命名的包)的全名。你的包名称必须在安装了Android系统上的所有软件包是唯一的。您可以从应用程序的名称或公司域名独立编辑此值。
◦项目的位置是您的系统保存项目文件的目录。
2.Under Configure your new project, fill in the fields as shown in figure 1 and click Next.
It will probably be easier to follow these lessons if you use the same values as shown.
◦Application Name is the app name that appears to users. For this project, use "My First App."
◦Company domain provides a qualifier that will be appended to the package name; Android Studio will remember this qualifier for each new project you create.
◦Package name is the fully qualified name for the project (following the same rules as those for naming packages in the Java programming language). Your package name must be unique across all packages installed on the Android system. You can  Edit this value independently from the application name or the company domain.
◦Project location is the directory on your system that holds the project files.

3.在选择外形您的应用程序将运行,检查框的手机和平板电脑。
3.Under Select the form factors your app will run on, check the box for  Phone and Tablet.

4.对于最小的SDK,选择API 8:Android 2.2(升级Froyo)。
所需的最低SDK的是Android的早期版本,您的应用程序支持,使用API级别表示。为了支持尽可能多的设备尽可能,你应该将其设置为可用,让您的应用程序,以提供其核心功能集的最低版本。如果你的应用程序中的任何功能只能在较新版本的Android,它是不是应用程序的核心功能集的关键,您可以启用在支持它(在支持不同平台版本讨论)的版本上运行,只有当该功能。
4.For Minimum SDK, select API 8: Android 2.2 (Froyo).
The Minimum Required SDK is the earliest 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).

5.将所有其他选项(电视,磨损和玻璃)选中,然后单击下一步。
5.Leave all of the other options (TV, Wear, and Glass) unchecked and click Next.

活动
Activities

活动是在Android框架的显着特征之一。活动为用户提供访问您的应用程序,并可能有很多的活动。一个应用程序通常将具有在用户启动应用程序,当她选择一些内容,以查看,例如用于另一个活动,并且当她执行该应用中的其它任务的其他活动的主要活动。看到活动的详细信息。
An activity is one of the distinguishing features of the Android framework. Activities provide the user with access to your app, and there may be many activities. An application will usually have a main activity for when the user launches the application, another activity for when she selects some content to view, for example, and other activities for when she performs other tasks within the app. See  Activities for more information.

6.在添加一个活动项目,选择空白活动,然后单击下一步。
6.Under Add an activity to your project, select Blank Activity and click Next.

7.在描述新的活动项目,离开领域,因为它们并单击Finish。
7.Under Describe the new activity for your project, leave the fields as they are and click Finish.

你的Android项目现在是一个基本的“Hello World”的应用程序,包含了一些默认的文件。花一点时间来审查最重要的:
Your Android project is now a basic "Hello World" app that contains some default files. Take a moment to review the most important of these:

app/src/main/res/layout/activity_my.xml
这是给你添加的,当你创建 Android  Studio中的项目活动的XML布局文件。继新项目的工作流程,Android Studio介绍该文件同时具有文本视图和屏幕UI的预览。该文件包括了一些默认设置和显示的消息,一个TextView元素“世界,你好!”
This is the XML layout file for the activity you added when you created the project with Android Studio. Following the New Project workflow, Android Studio presents this file with both a text view and a preview of the screen UI. The file includes some default settings and a TextView element that displays the message, "Hello world!"

app/src/main/java/com.mycompany.myfirstapp/MyActivity.java
该文件选项卡出现在Android Studio时新建项目的工作流程完成。当您选择的文件,你看到你创建活动的类定义。当你构建和运行应用程序,活动类开始活动,并加载布局文件,上面写着的“Hello World!”
A tab for this file appears in Android Studio when the New Project workflow finishes. When you select the file you see the class definition for the activity you created. When you build and run the app, the Activity class starts the activity and loads the layout file that says "Hello World!"

app/src/res/AndroidManifest.xml
清单文件描述了应用程序的基本特征,并确定它的每一个组成部分。当你遵循这些教训,你会再次讨论这个文件,并给您添加更多的组件
The manifest file describes the fundamental characteristics of the app and defines each of its components. You'll revisit this file as you follow these lessons and add more components to your

app.app/build.gradle
Android Studio使用Gradle编译和建立自己的应用程序。有对项目中的每个模块,以及用于整个项目build.gradle文件build.gradle文件。通常情况下,你只关心该模块的build.gradle文件,在这种情况下,应用程序或应用程序模块。这是你的应用程序的构建依赖关系设置,包括defaultConfig设置:
•compiledSdkVersion是平台版本对您将编译您的应用程序。默认情况下,它被设置为Android系统的最新版本在你的SDK。 (这应该是Android 4.1或更高版本;如果没有这样一个版本,你必须使用SDK管理器中安装一个。)你还可以建立自己的应用程序,以支持旧版本,但这种设置到最新版本,您可以要启用新功能和优化的应用程序为最新设备的用户体验。
•applicationID是您在新建项目工作流程中指定的应用程序的完全限定包名。
•minSdkVersion是你指定的最低SDK版本的新项目工作流程中。这是您的应用程序支持Android  SDK的最早版本。
•targetSdkVersion表示最高版本的Android与您已经测试您的应用程序。由于Android 新版本可用,您应该测试您的应用程序的新版本和更新此值,以匹配最新的API等级,从而采取新的平台功能。欲了解更多信息,请阅读支持不同平台版本。
Android Studio uses Gradle to compile and build your app. There is a build.gradle file for each module of your project, as well as a build.gradle file for the entire project. Usually, you're only interested in the build.gradle file for the module, in this case the app or application module. This is where your app's build dependencies are set, including the defaultConfig settings: •compiledSdkVersion 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 this to the latest version allows you to enable new features and optimize your app for a great user experience on the latest devices.
•applicationId is the fully qualified package name for your application that you specified during the New Project workflow.
•minSdkVersion is the Minimum SDK version you specified during the New Project workflow. This is the earliest version of the Android SDK that your app supports.
•targetSdkVersion indicates the highest version of Android with which you have tested 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 and thereby take advantage of new platform features. For more information, read Supporting Different Platform Versions.

看到生成项目与Gradle有关Gradle的更多信息。
See Building Your Project with Gradle for more information about Gradle.

Note also the /res subdirectories that contain the resources for your application:
还需要注意的是包含应用程序的资源/ RES子目录:
drawable-hdpi/
目录中可绘制对象(如位图)这是专为高密度(hdpi)屏幕。其他绘制目录包含专为其他屏幕密度资产。在这里,你会发现,当你运行默认显示的ic_launcher.png
Directory for drawable objects (such as bitmaps) that are designed for high-density (hdpi) screens. Other drawable directories contain assets designed for other screen densities. Here you'll find the ic_launcher.png that appears when you run the default

app.layout/
目录中定义您的应用程序的用户界面一样activity_my.xml,上面所讨论的,它描述了MyActivity类的基本的布局文件。
Directory for files that define your app's user interface like activity_my.xml, discussed above, which describes a basic layout for the MyActivity class.

values/
目录中包含资源的集合其他XML文件,比如字符串和颜色的定义。在strings.xml中文件定义的“Hello world!”字符串当您运行默认应用程序显示。
为了运行应用程序,继续下一课。...
Directory for other XML files that contain a collection of resources, such as string and color definitions. The strings.xml file defines the "Hello world!" string that displays when you run the default app.
To run the app, continue to the next lesson.

 

创建使用命令行工具项目

Create a Project with Command Line Tools

-------------------------------------------------- ------------------------------

如果你不使用Android Studio IDE,您可以使用SDK工具从命令行来创建项目:
If you're not using the Android Studio IDE, you can instead create your project using the SDK tools from a command line:

1.更改目录到了Android SDK的工具/路径。
1.Change directories into the Android SDK’s tools/ path.

2.Execute:Android的目标清单
2.Execute: android list targets
这将打印,你已经下载了你的SDK可用Android 平台列表。找到对您要编译您的应用程序的平台。记下目标的ID。我们建议您选择可能的最高版本。你仍然可以建立自己的应用程序,以支持旧版本,但构建目标设置到最新版本,您可以优化您的应用程序的latest设备。
This prints a list of the available Android platforms that you’ve downloaded for your SDK. Find the platform against which you want to compile your app. Make a note of the target 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.

如果您没有看到列出的任何目标,你需要一些使用Android SDK管理器工具安装。请参阅添加SDK软件包。
If you don't see any targets listed, you need to install some using the Android SDK Manager tool. See Adding SDK Packages.

3.Execute:Android的创建项目--target<目标ID>--name MyFirstApp\
--path<路径到工作区>/ MyFirstApp--activity MyActivity\
--package com.example.myfirstapp
3.Execute: android create project --target <target-id> --name MyFirstApp \
--path <path-to-workspace>/MyFirstApp --activity MyActivity \
--package com.example.myfirstapp

替换<目标ID>与目标列表(从以前的步骤)的ID和替换<路径到工作区>与要保存你的Android项目的位置。
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 Android projects.

提示:添加的平台工具/以及工具/目录到PATH环境变量。
Tip: Add the platform-tools/ as well as the tools/ directory to your PATH environment variable.

你的Android项目现在是一个基本的“Hello World”的应用程序,包含了一些默认的文件。为了运行应用程序,继续下一课。
Your Android project is now a basic "Hello World" app that contains some default files. To run the app, continue to the next lesson.

本文翻译自:https://developer.android.com/training/basics/firstapp/creating-project.html

时间: 2024-11-08 19:40:30

Android官方入门文档[1]创建一个Android项目的相关文章

Android官方入门文档[16]创建一个Fragment代码片段

Android官方入门文档[16]创建一个Fragment代码片段   Creating a Fragment创建一个Fragment代码片段   This lesson teaches you to1.Create a Fragment Class2.Add a Fragment to an Activity using XML You should also read•Fragments 这节课教你1.创建一个Fragment代码片段类2.使用XML来添加一个Fragment代码片段给一个活

Android官方入门文档[12]启动一个活动

Android官方入门文档[12]启动一个活动 Starting an Activity启动一个活动 This lesson teaches you to1.Understand the Lifecycle Callbacks2.Specify Your App's Launcher Activity3.Create a New Instance4.Destroy the Activity 这节课教你1.了解生命周期回调2.指定您的应用程序的启动活动3.创建一个新实例4.销毁活动 You sho

Android官方入门文档

Android官方入门文档   欢迎来到为Android开发者的培训.在这里,你会发现套课中,描述了如何实现代码示例中的应用程序,你可以重复使用一个特定的任务类.类被组织成可以在左侧导航的顶层看到几个组.这第一组,入门,教你最基本的Android应用程序的开发.如果你是一个新的Android应用程序开发者,你应该按照顺序完成这些课程. 如果你认为你可能更喜欢通过互动视频培训学习的基础知识,看看这个预告片在Android开发的基础的一门课程. Getting Started   Welcome t

Android官方入门文档[4]启动另一个Activity

Android官方入门文档[4]启动另一个Activity   Starting Another Activity启动另一个Activity This lesson teaches you to1.Respond to the Send Button2.Build an Intent 3.Create the Second Activity4.Receive the Intent5.Display the Message You should also read•Installing the S

Android官方入门文档[14]停止和重新启动一个Activity活动

Android官方入门文档[14]停止和重新启动一个Activity活动 Stopping and Restarting an Activity停止和重新启动一个Activity活动   This lesson teaches you to1.Stop Your Activity2.Start/Restart Your Activity You should also read•Activities 这节课教你1.停止您的Activity活动2.启动/重新启动您的Activity活动 你也应该阅

Android官方入门文档[2]运行你的应用程序

Android官方入门文档[2]运行你的应用程序   Running Your App运行你的应用程序   This lesson teaches you to1.Run on a Real Device2.Run on the Emulator You should also read•Using Hardware Devices•Managing AVDs with AVD Manager•Managing Projects 这节课教你1.运行在真实设备2.运行在模拟器 你也应该阅读•使用硬

Android官方入门文档[7]样式化操作栏

Android官方入门文档[7]样式化操作栏   Styling the Action Bar样式化操作栏   This lesson teaches you to1.Use an Android Theme2.Customize the Background3.Customize the Text Color4.Customize the Tab Indicator You should also read•Styles and Themes•Android Action Bar Style

Android官方入门文档[9]支持不同的语言

Android官方入门文档[9]支持不同的语言 Supporting Different Languages支持不同的语言   This class teaches you to1.Create Locale Directories and String Files2.Use the String Resources You should also read•Localization Checklist•Localization with Resources 该课程教你1.创建区域设置目录和文件

Android官方入门文档[10]支持不同的屏幕

Android官方入门文档[10]支持不同的屏幕   Supporting Different Screens支持不同的屏幕   This lesson teaches you to1.Create Different Layouts2.Create Different Bitmaps You should also read•Designing for Multiple Screens•Providing Resources•Iconography design guide 这节课教你1.创建