转载请注明出处:http://blog.csdn.net/dawanganban/article/details/9822431
Building Your First App
GETSTARTED
DEPENDENCIESAND PREREQUISITES
·Android SDK
·ADT Plugin20.0.0 or higher (if you're
usingEclipse)
Welcome toAndroid application development!
This classteaches you how to build your first Android app. You’ll learn how to create anAndroid project and run a debuggable version of the app. You'll also learn somefundamentals of Android app design, including
how to build a simple userinterface and handle user input.
Before you startthis class, be sure you have your development environment set up. You need to:
1.Download the Android SDK.
2.Install the ADT plugin for Eclipse (if you’ll use theEclipse IDE).
3.Download the latest SDK tools and platforms using the SDKManager.
If you haven'talready done these tasks, start by downloading theAndroid SDKandfollowing
the install steps. Once you've finished the setup, you're ready tobegin this class.
This class usesa tutorial format that incrementally builds a small Android app that teachesyou some fundamental concepts about Android development, so it's important thatyou follow each step.
建立你的第一个应用程序
·android
sdk
·ADT插件20
0 0或更高(如果您使用Eclipse)
欢迎来到Android应用程序开发!
本教程会教你如何建立你的第一个Android应用程序。您将学习如何创建一个Android项目并调试应用程序,你还将学习一些Android应用程序设计的基础,包括如何构建一个简单的用户界面和处理用户输入。
在你开始本教程之前,请确保你已经搭建好开发环境。你需要:
1.下载Android SDK。
2.Eclipse的ADT插件安装 (如果你使用的是Eclipse
IDE)。
3.下载最新的SDK工具和平台使用SDK管理器
如果您尚未完成这些任务,开始下载android
sdk并完成安装步骤。如果你完成了设置,准备开始本课程的学习。
本课程将通过使用一个小型的android应用,教你一些基本概念和安卓开发过程,所以遵循每一步的操作都至关重要。
开始第一课;
Creating an Android Project
PREVIOUSNEXT
THIS LESSONTEACHES YOU TO
1.
Create a Project with Eclipse
2.
Create a Project with Command Line Tools
·
Installing the SDK
·
Managing Projects
An Android projectcontains all the files that comprise the source code for your Android app. TheAndroid SDK tools make it easy to start a new Android project with a set ofdefault project directories and files.
This lesson showshow to create a new project either using Eclipse (with the ADT plugin) or usingthe SDK tools from a command line.
Note:You shouldalready have the Android SDK installed, and if you're using Eclipse, you shouldalso have theADT
plugininstalled (version 21.0.0 or higher). If you don't have these, follow theguide toInstalling the Android SDKbefore
you start this lesson.
Create a Project with Eclipse
1.ClickNewinthe
toolbar.
2.In the window thatappears, open theAndroidfolder,selectAndroid Application Project,and clickNext.
Figure 1.The New Android App Project wizard in Eclipse.
3.Fill in the formthat appears:
oApplicationNameis the app name thatappears to users. For this project, use "My First App."
oProjectNameis the name of your projectdirectory and the name visible in Eclipse.
oPackageNameis the package namespacefor your app (following the same rules as packages in the Java programminglanguage). Your package name must be unique across all packages installed onthe
Android system. For this reason, it's generally best if you use a name thatbegins 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 GooglePlay using the "com.example" namespace.
oMinimumRequired SDKis the lowest version ofAndroid that your app supports, indicated using theAPI
level. To support as many devices as possible, you should set this to thelowest 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 andit's not critical
to the app's core feature set, you can enable the featureonly when running on the versions that support it (as discussed inSupporting
Different Platform Versions). Leave this set to the default value for this project.
oTargetSDKindicates the highestversion of Android (also using theAPI
level) with which you have tested with your application.
As new versions of Android become available, you shouldtest your app on the new version and update this value to match the latest APIlevel in order to take advantage of new platform features.
oCompileWithis the platform versionagainst which you will compile your app. By default, this is set to the latestversion 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 usingtheSDK Manager). You can still build your
app to support older versions, but setting thebuild target to the latest version allows you to enable new features andoptimize your app for a great user experience on the latest devices.
oThemespecifies the Android UI style to apply for yourapp. You can leave this alone.
ClickNext.
4.On the next screento configure the project, leave the default selections and clickNext.
5.The next screencan help you create a launcher icon for your app.
You can customize an icon in several ways and the toolgenerates an icon for all screen densities. Before you publish your app, youshould be sure your icon meets the specifications defined in theIconographydesign
guide.
ClickNext.
6.Now you can selectan activity template from which to begin building your app.
For this project, selectBlankActivityandclickNext.
7.Leave all thedetails for the activity in their default state and clickFinish.
Your Androidproject is now set up with some default files and you’re ready to beginbuilding the app. Continue to thenext
lesson.
Create a Project with Command Line Tools
If you're notusing the Eclipse IDE with the ADT plugin, you can instead create your projectusing the SDK tools from a command line:
1.Change directoriesinto the Android SDK’stools/path.
2.Execute:
This prints a list of the available Android platformsthat you’ve downloaded for your SDK. Find the platform against which you wantto compile your app. Make a note of the target id. We recommend that you selectthe highest version possible. You
can still build your app to support olderversions, but setting the build target to the latest version allows you tooptimize your app for the latest devices.
If you don't see any targets listed, you need to installsome using the Android SDK Manager tool. SeeAdding
Platforms and Packages.
3.Execute:
4. android create project --target<target-id> --name MyFirstApp \
5. --path<path-to-workspace>/MyFirstApp --activity MainActivity \
6. --package com.example.myfirstapp
Replace<target-id>with an id from the list of targets (from the previous step) andreplace<path-to-workspace>with the location in which you want to save yourAndroid projects.
Your Androidproject is now set up with several default configurations and you’re ready tobegin building the app. Continue to thenext
lesson.
Tip:Addtheplatform-tools/as well as thetools/directory to yourPATHenvironmentvariable.
创建一个Android项目
1. 使用Eclipse创建一个项目
2. 使用命令行工具创建项目
·安装SDK
·管理项目
Android项目包含的所有文件,包括你的Android应用程序的源代码。AndroidSDK的工具,可以让构建Android项目与默认项目目录和文件变的更便捷和简单。
本课将说明如何使用Eclipse ADT插件或使用SDK命令行工具创建一个新的项目。
注意:你应该已经安装了Android SDK,如果你使用Eclipse,你应该也有安装ADT插件(21.0.0或更高版本)。如果你没有这些,按照安装指南安装Android
SDK,然后再开始本课学习。
使用Eclipse创建一个项目
1.点击“新建”在工具栏。
2.在出现的窗口中,打开Android的文件夹,选择“Android Application,并单击”下一步“。
图1:新的Android应用程序在Eclipse项目向导。
3.填写的形式出现:
oApplication Name给用户展示的应用程序的名称。对于这个项目,使用“My
First App”
oProject Name您的项目在Eclipse中可见的目录和名称。
oPackage Name是包的命名空间,为您的应用程序(在Java编程语言遵循相同的包规则)。你的包的名称必须是在Android系统上安装的所有软件包中唯一的。出于这个原因,如果您使用与您的组织或出版实体的反向域名作为包名通常是最好的。对于这个项目,你可以使用例如“com.example.myfirstapp”但是,您不能使用
“com.example”作为命名空间来发布您的应用程序。
oMinimumRequired SDK您的应用程序支持的AndroidSDK是最低版本,表明API的版本高低。为了尽可能的支持多的设备,你应该设定这个最低版本为可以让您的应用程序提供其核心功能的最低版本。如果您的应用程序的核心功能集在新版本的Android和其他版本都支持,当在不同版本可以支持时可以使用该功能(如支持不同的平台版本)。将此设定为这个项目的默认值。
oTarget SDK表明您测试您的应用程序的Android(也使用API级别)的最高版本。
随着新版本Android的使用,您应该在新版本上测试应用程序来更新此值,以符合最新的API级别,以充分利用新的平台功能。
oCompile With编译您的应用程序的平台版本。默认情况下,此设置为您的Android
SDK提供的最新版本。(应该是Android 4.1或更高版本,如果你没有这样的版本,您必须安装一个使用SDK管理器)。您也可以建立你的应用程序来支持旧版本,但设置构建目标到最新版本可以让用户体验最新设备的功能和您对应用程序的优化。
oTheme指定申请您的应用程序的Android UI风格。你可以忽略这一项。
单击“下一步”。
4.在下一屏幕配置项目,保留默认选项,并单击“下一步”。
5.下一个屏幕,可以帮助您创建一个启动你的应用程序的图标。
您可以自定义图标在几个方面,该工具会生成一个图标,所有的屏幕密度。在您发布您的应用程序之前,你应该确保你的图标符合设计规范。
单击“下一步”。
6.现在您可以选择构建应用程序的动态模板。
对于这个项目,选择BlankActivity,并单击“下一步”。
7.保留所有为默认,并单击Finish。
现在你的Android项目生成了一些默认的文件,准备好开始构建你的应用程序。继续下一课。
使用命令行工具创建项目
如果你不使用Eclipse IDE ADT插件,可以改为使用SDK命令行工具来创建你的项目:
1.改变当前目录到Android SDK的tools/路径。
2.执行:
Android listtargets
打印你已经下载的SDK可用的Android平台列表。找到编译你的应用程序的平台。请记下平台的id。我们建议您选择可能的最高版本。您也可以建立支持旧版本的应用程序,但设置构建目标到最新版本,可以优化你的应用程序。
如果你没有看到任何平台列表,你需要使用Android SDK管理器安装一些工具。请参阅添加平台和软件包。
3.执行:
android create project --target <target-id> --name MyFirstApp \
--path <path-to-workspace>/MyFirstApp --activity MainActivity \
--package com.example.myfirstapp
用目标平台的id(前面的步骤)更换<target-id>,并更换<path-to-workspace>为要保存你的Android项目的位置。
现在你的Android项目设置了几个默认的配置,你准备好开始构建应用程序。继续下一课。
分享到:
相关推荐
Android学习笔记(一)——创建第一个Android项目 Android学习笔记(二)android studio基本控件及布局(实现图片查看器) Android学习笔记(三)android studio中CheckBox自定义样式(更换复选框左侧的勾选图像) ...
移动操作系统原理与实践——基于Java语言的Android应用开发 目录 基础篇 第1章移动操作系统概论 1.1操作系统的原理与概念 1.1.1隐藏硬件细节 ...第3章第一个Android应用程序 3.1使用Android Studio工具创建项目
第1章 Android简介 1.1 手机操作系统 1.2 Android起源 1.3 Android特征 1.4 Android体系结构 1.4.1 应用层 1.4.2 应用框架层 1.4.3 系统库层 1.4.4 内核层 1.5 小结 练习 第2章 Android开发环境 2.1 ...
hello world视频教程,希望能够学习者提供帮助,实现对Android基础知识的掌握与理解,为后续学习做好铺垫,实现Android知识的灵活运用
动手学Android之三——第一个界面例子程序,希望大家继续支持我,给我提出宝贵意见!
黑马程序员——Android移动开发源码
即实战演练的全部代码,加图片资源。
3.1 第一个Android应用程序 3.2 Android项目结构 3.3 APK文件结构 3.4 Android应用程序权限 3.5 Activity及其生命周期 3.5.1 什么是Activity 3.5.2 Activity生命周期 3.6 Intent简介 3.6.1 Intent...
创建 第一个Android 工程 1)启动 Eclipse,菜单栏选择 File -> New -> Project…。 2)在 New Project 窗口的列表中找到 Android,选择 Android Application Project。 3)输入前三项项目信息,之后选项保持默认...
Google.Android开发入门与实战第12章.Android综合案例一——RSS阅读器实例
Android开发基础,讲述了Android开发环境的搭建、Android常用工具的使用和第一个Android应用程序的开发 第二篇 技术篇 第3章 Android中的资源访问 Android 中的资源访问,讲述了如何定义和访问Android中的外部...
第1章 掀起你的盖头来——初识Android 1.1 认识Android 1.2 Android的背景 1.2.1 Android的历史 1.2.2 Android的发展 1.3 我的Android我做主 1.3.1 开发基于Android平台的应用 1.3.2 参加Android开发者大赛 1.3.3 ...
Android学习笔记(一)——创建第一个Android项目 Android学习笔记(二)android studio基本控件及布局(实现图片查看器) Android学习笔记(三)android studio中CheckBox自定义样式(更换复选框左侧的勾选图像) ...
NULL 博文链接:https://ylxy3058.iteye.com/blog/2227814
《新手学html5 移动开发——面向ios 和android 平台》的第i部分从第1章~第8章。第1章首先介绍了html4.01的基本原理,第2章通过生动且复杂的教程介绍了html5,其中包含了大量实例和屏幕截图。第3章详细介绍了css。在...
《老罗Android视频教程(第一季)》的视频一共分为15个章节, 涵盖了Android入门、常用UI布局介绍、HTTP编程、 XML与Json数据解析、JDBC与Web编程、常用UI控件、 数据储存与文件操作、对话框、通知、菜单、 ...
Android系统级深入开发——移植与调试第一部分
第1章 android平台上的c++入门 1 第2章 深入了解androidndk 35 第3章 用jni实现与原生代码通信 57 第4章 使用swig自动生成jni代码 81 第5章 日志、调试及故障处理 111 第6章 bionic api入门 135 第7章 原生线程 155 ...
Android移动应用设计与开发——刘博 原书配套源代码。 全书共12章节 前三章节主要介绍Android和开发环境的搭建 源码主要包括第四、五、六、七、八、九等章节 还有一个服务器和客户端的大案例说明。
Android 是一个专门针对移动设备的软件集,它包括一个操作系统,中间件和一些重要的应用程序。 Beta 版 的 Android SDK 提供了在 Android 平台上使用 JaVa 语言进行 Android 应用开发必须的工具和 API 接口。 特性 ...