Android官方文档翻译 四 1.2Running Your App
Running Your App
If you followed the previous lesson to create an Android project, it includes a default set of “Hello World” source files that allow you to immediately run the app.
如果你跟着前面的课程创建了一个Android项目,这个项目包括一系列默认的“Hello World”资源文件,你就可以立即开始运行你的app了。
How you run your app depends on two things: whether you have a real Android-powered device and whether you’re using Eclipse. This lesson shows you how to install and run your app on a real device and on the Android emulator, and in both cases with either Eclipse or the command line tools.
要想运行你的app必须具备以下两个条件:你是否有一个使用Android操作系统的真机设备,你是否使用Eclipse。这节课将教给你如何在一个真机上或者一个Android模拟器上安装并且运行你的app,以下两种情况我们都会说到:在Eclipse上和在命令行工具里。
Before you run your app, you should be aware of a few directories and files in the Android project:
在你开始运行你的app以前,你应该了解在你的Android项目中有以下一些目录和文件:
AndroidManifest.xml
The manifest file describes the fundamental characteristics of the app and defines each of its components. You’ll learn about various declarations in this file as you read more training classes.
清单文件记述了对于app的基本特性和定义了它的每个组分。如果你继续读后面的更多练习课程,你将在这个文件中学会各种各样的声明。
One of the most important elements your manifest should include is the element. This declares your app’s compatibility with different Android versions using the android:minSdkVersion and android:targetSdkVersion attributes. For your first app, it should look like this:
你的清单文件中应该包含的最重要的元素之一就是元素。这个使用 android:minSdkVersion 和 android:targetSdkVersion属性来声明你的app对于不同Android版本的兼容性。对于你的第一个app,它应该看起来像以下这样:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />
...
</manifest>
- You should always set the android:targetSdkVersion as high as possible and test your app on the corresponding platform version. For more information, read Supporting Different Platform Versions.
你应该总是设置android:targetSdkVersion这个属性尽可能的高,并且在相应的平台版本上测试你的app。想获得更多的信息,请阅读“Supporting Different Platform Versions”。
src/
- Directory for your app’s main source files. By default, it includes an Activity class that runs when your app is launched using the app icon.
这是你app的主要的资源文件。默认情况下,它包含一个Activity类,当你的app通过应用图标来运行时会用到它。
res/
Contains several sub-directories for app resources. Here are just a few:
包含了你的app资源的几个子目录。以下列取了几个:
drawable-hdpi/
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.
drawable对象(就如位图对象一样)的目录,它是为高密度(hdpi)的屏幕设置的。其它的drawable目录包含的资源是位其它密度的屏幕设置的。
layout/
Directory for files that define your app’s user interface.
定义你的app的用户界面的文件目录。
values/
Directory for other various XML files that contain a collection of resources, such as string and color definitions.
其它的一些各种各样的XML文件目录,它包含许多资源,比如string(字符)和color(颜色)的定义。
When you build and run the default Android app, the default Activity class starts and loads a layout file that says “Hello World.” The result is nothing exciting, but it’s important that you understand how to run your app before you start developing.
当你创建好并且运行了默认的Android app后,默认的Activity类会开始运行并且加载一个显示“Hello World”的layout文件。这个结果可能没有什么令人兴奋的,但是在你开始开发之前,它对于你了解如何运行你的app是非常重要的。
Run on a Real Device
在一个真机上运行
If you have a real Android-powered device, here’s how you can install and run your app:
如果你有一个搭载Android系统的真机,这里将告诉你如何开始安装和运行你的app:
Plug in your device to your development machine with a USB cable. If you’re developing on Windows, you might need to install the appropriate USB driver for your device. For help installing drivers, see the OEM USB Drivers document.
用一个USB数据线把你的Android设备连接到你开发所用的机器上。如果你在Windows上进行开发,你可能需要安装适合你的Android设备的USB驱动。如果你对安装设备不太了解,请看OEM USB Drivers文档。
Enable USB debugging on your device.
在你的Android设备上打开USB调试模式
- On most devices running Android 3.2 or older, you can find the option under Settings > Applications > Development.
在大多数搭载Android 3.2或者更低版本的Android设备上,在 设置 > 应用程序 > 开发 中你可以找到此选项
- On Android 4.0 and newer, it’s in Settings > Developer options.
在搭载Android 4.0或者更高版本的机器上,你可以在 设置 > 开发者选项中找到此选项。
Note: On Android 4.2 and newer, Developer options is hidden by default. To make it available, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.
注意:在Android 4.2或者更高的版本上,开发者选项默认是隐藏的。想让其显示,你可以按 设置 > 关于手机,在版本号选项上连续点击7次。返回前一页,你将可以找到开发者选项。
To run the app from Eclipse:
从Eclipse中运行你的app
Open one of your project’s files and click Run from the toolbar.
打开一个项目文件,在工具栏上点击 Run。
In the Run as window that appears, select Android Application and click OK.
在运行后出现的窗口中,选择你用来编译的Android设备,然后点击OK。
Eclipse installs the app on your connected device and starts it.
Eclipse将在你已经连接好的设备上安装app并且运行。
Or to run your app from a command line:
或者,你也可以从命令行来运行你的app:
Change directories to the root of your Android project and execute:
进入你的Android项目的根目录,执行:
ant debug
Make sure the Android SDK platform-tools/ directory is included in your PATH environment variable, then execute:
确保你的PATH环境变量中包含 Android SDK platform-tools/ 目录,然后执行:
adb install bin/MyFirstApp-debug.apk
On your device, locate MyFirstActivity and open it.
在你的设备上,找到 MyFirstActivity ,然后打开它。
That’s how you build and run your Android app on a device! To start developing, continue to the next lesson.
这就是如何创建并且在Android设备上运行你的Android app。要开始开发,继续下一节课程吧。
Run on the Emulator
在模拟器上运行
Whether you’re using Eclipse or the command line, to run your app on the emulator you need to first create an Android Virtual Device (AVD). An AVD is a device configuration for the Android emulator that allows you to model different devices.
无论你是使用Eclipse还是使用命令行,如果你想在模拟器上运行你的app你首先都需要创建一个Android模拟设备(AVD)。AVD是一个Android模拟器的设备配置,它可以让你去模拟不同的设备。
To create an AVD:
创建一个AVD
Launch the Android Virtual Device Manager:
运行Android 虚拟设备管理器
In Eclipse, click Android Virtual Device Manager from the toolbar.
在Eclipse中,在工具栏里点击 Android Virtual Device Manager。
*. From the command line, change directories to /tools/ and execute:
在命令行里,改变目录到 /tools/,然后运行:android avd
In the Android Virtual Device Manager panel, click New.
在Android Virtual Device Manager面板中,点击New。
- Fill in the details for the AVD. Give it a name, a platform target, an SD card size, and a skin (HVGA is default).
填写AVD的详情。给它一个名字,一个目标平台,一个SD卡的大小和一个皮肤(默认是HVGA)。
- Click Create AVD.
点击创建AVD。 - Select the new AVD from the Android Virtual Device Manager and click Start.
从Android Virtual Manager中选择一个新的AVD设备,然后点击Start。 - After the emulator boots up, unlock the emulator screen.
模拟器启动以后,把模拟器的屏幕解锁。
To run the app from Eclipse:
从Eclipse中运行你的app
Open one of your project’s files and click Run from the toolbar.
打开一个项目文件,在工具栏上点击 Run。
In the Run as window that appears, select Android Application and click OK.
在运行后出现的窗口中,选择你用来编译的Android设备,然后点击OK。
Eclipse installs the app on your connected device and starts it.
Eclipse将在你已经连接好的设备上安装app并且运行。
Or to run your app from a command line:
或者,你也可以从命令行来运行你的app:
Change directories to the root of your Android project and execute:
进入你的Android项目的根目录,执行:
ant debug
Make sure the Android SDK platform-tools/ directory is included in your PATH environment variable, then execute:
确保你的PATH环境变量中包含 Android SDK platform-tools/ 目录,然后执行:
adb install bin/MyFirstApp-debug.apk
On your device, locate MyFirstActivity and open it.
在你的设备上,找到 MyFirstActivity ,然后打开它。
That’s how you build and run your Android app on a device! To start developing, continue to the next lesson.
这就是如何创建并且在Android设备上运行你的Android app。要开始开发,继续下一节课程吧。
这是我自己翻译的,如果您发现其中有重要翻译错误,敬请指出。万分感谢!
Android官方文档翻译 四 1.2Running Your App的更多相关文章
- android官方文档翻译(不断更新中。。。)
最近在自学android,抽空把官方文档的guide跟training差不多看了一遍,又对比了一些书籍,感觉还是官方文档讲得比较好,所以自己计划把官方文档翻译一下,方便自己的知识巩固以及复习查找,由于 ...
- Android官方文档翻译 十五 3.3Supporting Different Platform Versions
Supporting Different Platform Versions 支持不同的平台版本 This lesson teaches you to 这节课教给你 Specify Minimum a ...
- Android官方文档翻译 三 1.1Creating an Android Project
Creating an Android Project 创建一个Android项目 An Android project contains all the files that comprise th ...
- Android官方文档翻译 八 2.1Setting Up the Action Bar
Setting Up the Action Bar 建立Action Bar This lesson teaches you to 这节课教给你 Support Android 3.0 and Abo ...
- Android官方文档翻译 十四 3.2Supporting Different Screens
Supporting Different Screens 支持不同的屏幕 This lesson teaches you to 这节课教给你 Create Different Layouts 创建不同 ...
- Android官方文档翻译 二 1.Building Your First App
Building Your First App 创建你的第一个App项目 Dependencies and prerequisites 依赖关系和先决条件 * Android SDK * ADT Pl ...
- Android官方文档翻译 九 2.2Adding Action Buttons
Adding Action Buttons 增加动作按钮 This lesson teaches you to 这节课教给你 Specify the Actions in XML 在XML中指定动作 ...
- Android官方文档翻译 十七 4.1Starting an Activity
Starting an Activity 开启一个Activity This lesson teaches you to 这节课教给你 Understand the Lifecycle Callbac ...
- Android官方文档翻译 十六 4.Managing the Activity Lifecycle
Managing the Activity Lifecycle 管理activity的生命周期 Dependencies and prerequisites 依赖关系和先决条件 How to crea ...
随机推荐
- iNeuOS工业互联网操作系统,发布3.6.4版本:云端安全控制和实时日志功能,附Chrome、Firefox和Edge浏览器测试性能对比
目 录 1. 概述... 2 2. 平台演示... 2 3. 云端控制和实时日志设计和技术... 2 4. 实时日志测试... 2 1. 概述 ...
- CF918B Radio Station 题解
Content 有 \(n\) 个形如 \(a_i.b_i.c_i.d_i\) 的 IP 地址.有 \(m\) 条命令,每条命令由一条字符串 \(s\) 和一个形如 \(p.q.r.s\) 的 IP ...
- CF1501A Alexey and Train 题解
Content 一列火车从 \(0\) 时刻开始从 \(1\) 号站出发,要经过 \(n\) 个站,第 \(i\) 个站的期望到达时间和离开时间分别为 \(a_i\) 和 \(b_i\),并且还有一个 ...
- SpringCloud使用GateWay网关前端请求请求跨域处理
增加配置类 CorsConfig.java import org.springframework.context.annotation.Bean; import org.springframework ...
- office2007(word2007)另存为pdf文档
默认office2007(word2007)是没有另存为pdf文档的功能的,需要安装插件 插件地址:https://yvioo.lanzous.com/iO5myedoceh 下载之后直接安装,安装成 ...
- Lucene 基础数据压缩处理
Lucene 为了使的信息的存储占用的空间更小,访问速度更快,采取了一些特殊的技巧,然 而在看 Lucene 文件格式的时候,这些技巧却容易使我们感到困惑,所以有必要把这些特殊 的技巧规则提取出来介绍 ...
- 【LeetCode】263. Ugly Number 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 除去2,3,5因子 日期 [LeetCode] 题目 ...
- 对XSS的插入的新了解,灵感来自天驿安全
此次针对的是通过Get请求进行插入的XSS语句,或者dom型的xss,也算是了解到的新的插入方式 首先,JavaScript语言中存在拼接性 可以通过代审后闭合前置语句进行self测试是否可以拼接 s ...
- ZooKeeper基础知识总结
数据模型 ZooKeeper数据模型是一个树状的数据结构,类似于文件系统:和文件系统的区别在于树中的每一个节点(叶子节点与非叶子节点)都可以保存数据,且每个节点的访问都必须从根节点开始,以斜线作为分隔 ...
- Java EE数据持久化框架 • 【第6章 MyBatis插件开发】
全部章节 >>>> 本章目录 6.1 MyBatis拦截器接口 6.1.1 MyBais拦截器接口介绍 6.1.2 MyBais拦截器签名介绍 6.1.3 实践练习 6.2 ...