晕死,写PPT写到十一点半,我只是想安安静静的写代码,写个毛线的PPT,写完还说不行,让重写,头都大了,哥现在只想做个coder而已,现在还是鱼肉,人为刀俎,不说了,不能第一天就挖坑不填.
Getting Started
Building Your First App
Creating an Android Project
创建一个工程,不能更熟了,从上到下依次是应用名称,工程名称,包名,最低sdk版本,最高版本,使用的编译版本,app的主题
当然也可以用命令行来进行创建
在tools/ 路径下输入
android list targets
可以打印出可用的target SDK版本.
如果要创建工程则使用:
android create project --target <target-id> --name MyFirstApp --path <path-to-workspace>/MyFirstApp --activity MainActivity --package com.example.myfirstapp
Running your Application 好困...
这节课主要是说在真机和模拟器上运行app,我们先要指定SDKversion
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> ... </manifest>
然后说了一下android project的目录结构
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. res/
- Contains several sub-directories for app resources. Here are just a few:
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.
layout/
- Directory for files that define your app‘s user interface.
values/
- Directory for other various XML files that contain a collection of resources, such as string and color definitions.
src/
app的源码文件夹,他是默认的,包括了一个activity,当你点击app图标的时候运行的就是这个activity.
res/
包含了许多app资源.其中包括:
drawable-hdpi/
drawable 对象的目录(比如位图),用于hdpi屏幕而设计的,其他的drawable目录包含了为其他屏幕密度设计的资源
layout/
app的用户界面目录.
values/
其他各种xml文件的目录,包含了一个资源的集合,比如string和颜色的定义.
接下来介绍了怎么在真机上运行app
- 加载android设备的驱动
- 开启手机的测试模式
也可以用命令行来运行
- Change directories to the root of your Android project and execute:
ant debug
- Make sure the Android SDK
platform-tools/
directory is included in yourPATH
environment variable, then execute:adb install bin/MyFirstApp-debug.apk
- On your device, locate MyFirstActivity and open it.
That‘s how you build and run your Android app on a device! To start developing, continue to the next lesson.
在模拟器上运行:
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 anAndroid Virtual Device (AVD). An AVD is a device configuration for the Android emulator that allows you to model different devices.
Figure 1. The AVD Manager showing a few virtual devices.
To create an AVD:
- Launch the Android Virtual Device Manager:
- In Eclipse, click Android Virtual Device Manager from the toolbar.
- From the command line, change directories to
<sdk>/tools/
and execute:android avd
- In the Android Virtual Device Manager panel, click 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).
- Click Create AVD.
- Select the new AVD from the Android Virtual Device Manager and click Start.
- After the emulator boots up, unlock the emulator screen.
To run the app from Eclipse:
- Open one of your project‘s files and click Run from the toolbar.
- In the Run as window that appears, select Android Application and click OK.
Eclipse installs the app on your AVD and starts it.
Or to run your app from the command line:
- Change directories to the root of your Android project and execute:
ant debug
- Make sure the Android SDK
platform-tools/
directory is included in yourPATH
environment variable, then execute:adb install bin/MyFirstApp-debug.apk
- On the emulator, locate MyFirstActivity and open it.
That‘s how you build and run your Android app on the emulator! To start developing, continue to the next lesson.
偷个懒,直接粘贴了...
这里的AVD 就是指模拟器 android virtual device