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

简介: Android官方入门文档[1]创建一个Android项目 创建一个Android项目 这节课教你1.创建与Android Studio中的一个项目2.

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

目录
相关文章
|
4月前
|
Web App开发 移动开发 小程序
"项目中mpaas升级到10.2.3 适配Android 14之后 app中的H5以及小程序都访问不了,
"项目中mpaas升级到10.2.3 适配Android 14之后 app中的H5以及小程序都访问不了,显示“网络不给力,请稍后再试”,预发内网版本不能使用,线上版本可以正常使用,这个是什么原因啊,是某些参数没有配置吗,还是说是一些参数改错了?
56 2
|
1月前
|
测试技术 API 调度
【Android 从入门到出门】第七章:开始使用WorkManager
【Android 从入门到出门】第七章:开始使用WorkManager
19 3
【Android 从入门到出门】第七章:开始使用WorkManager
|
1月前
|
存储 Android开发 C++
【Android 从入门到出门】第五章:使用DataStore存储数据和测试
【Android 从入门到出门】第五章:使用DataStore存储数据和测试
30 3
|
1月前
|
Android开发
【Android 从入门到出门】第四章:现代Android开发中的导航
【Android 从入门到出门】第四章:现代Android开发中的导航
22 2
【Android 从入门到出门】第四章:现代Android开发中的导航
|
1月前
|
XML API Android开发
【Android 从入门到出门】第三章:使用Hilt处理Jetpack Compose UI状态
【Android 从入门到出门】第三章:使用Hilt处理Jetpack Compose UI状态
26 4
|
1月前
|
存储 XML 编译器
【Android 从入门到出门】第二章:使用声明式UI创建屏幕并探索组合原则
【Android 从入门到出门】第二章:使用声明式UI创建屏幕并探索组合原则
47 3
|
1月前
|
存储 SQL 数据库
【Android 从入门到出门】第六章:使用Room数据库并测试
【Android 从入门到出门】第六章:使用Room数据库并测试
29 4
|
1月前
|
存储 Android开发
【Android 从入门到出门】第八章:分页入门指南
【Android 从入门到出门】第八章:分页入门指南
21 3
|
1月前
|
IDE Java 开发工具
【Android 从入门到出门】第一章:Android开发技能入门指南
【Android 从入门到出门】第一章:Android开发技能入门指南
62 3
|
2月前
|
JSON Java Go