|
本帖最后由 meigui 于 2011-8-30 22:28 编辑 第四部分: 源代码的各个文件
Android.mk 是整个工程的“Makefile”,其内容如下所示:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := samples
# Only compile source java files in this apk.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := HelloActivity
LOCAL_SDK_VERSION := current
include $(BUILD_PACKAGE)
# Use the following include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
这个文件在各个 Android 的工程中都是类似的,其中 LOCAL_PACKAGE_NAME 表示了这个包的名字。LOCAL_MODULE_TAGS 表示了模块的标,在这里使用的是samples,正式的应用程序(packages 目录中的应用)中多使用 eng development。
AndroidManifest.xml 是这个 HelloActivity 工程的描述文件,其内容如下所示: - <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.helloactivity">
<application android:label="He llo, Activity!">
<activity android:name="He lloActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
复制代码 其中 package 用于说明这个包的名称,android:labeapplication 中的内容是表示这个应用程序在界面上显示的标题,activity 中的 android:name 表示这个 Android 的活动的名称。
文件 src/com/example/android/helloactivity/HelloActivity.java 是程序主要文件,由 JAVA 语言
写成 - package com.example.android.helloactivity;
import android.app.Activity;
import android.os.Bundle;
public class HelloActivity extends Activity {
public HelloActivity() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hello_activity);
}
}
复制代码 com.example.android.helloactivity 表示的是这个包的名称, 在文件的头部引入了两个包android.app.Activity 是一个 Android 活动( Activity)包,每一个 Android 活动都需要继承Activity 类。包 android.os.Bundle 用于映射字符串的值。onCreate()是一个重载的函数,在这个函数中实现应用程序创建的所执行的过程。其中setContentView()设置当前的视图(View)。设置的方法是使用一个文件,这个文件因此决定了视图中包含的内容。这里使用的是R.layout.hello_activity,表示从 res/layout/目录中使用 hello_activity.xml 文件。
res/layout/hello_activity.xml 文件的内容如下所示: - <?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="18sp"
android:autoText="true"
android:capitalize="sentences"
android:text="@string/hello_activity_text_text" />
复制代码 其中定义了一个可编辑的文本( EditText),下面的各项其实是它的各种属性, android:text 表示这个文本的内 容 ,string/hello_activity_text_text 表 示 找 到 相 应 的 文 件 , 也 就 是 res/value/string.xml 文 件 中 的hello_activity_text_text 文本。
res/value/string.xml 的内容如下所示: - <?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello_activity_text_text">He llo, World!</string>
</resources>
复制代码 hello_activity_text_text 文本被 res/layout/hello_activity.xml 文件引用,正是应用程序运行时在
屏幕显示的文本。
Android ADB 工具使用
adb(Android Debug Bridge)是 Android 提供的一个通用调试工具,借助这个工具,我妈可以管理设备或手机模
拟器的状态。
adb 功能操作:
快速更新设备或手机模拟器中的代码,如应用或 Android 系统升级
在设备上运行 shell 命令
管理设备或手机模拟器上预定端口
在设备或手机模拟器上复制、粘贴文件
adb 常用操作:
安装应用到模拟器
adb install app.apk
Android 没有提供一个卸载应用的命令,只能手动删除:
adb shell
cd data/app
rm app.apk
进入设备或模拟器的 Shell
adb shell
通过以上命令,可以进入设备或模拟器的 shell 环境中,在这个 Linux Shell 中,你可以执行各种 Linux 的命令 ,
另外如果只想执行一条 shell 命令,可以采用以下方式:
adb shell [command]
如:
adb shell dmesg
会打印出内核的调试信息
发布端口
可以设置任意的端口号,做为主机向模拟器或设备的请求端口。如:
adb forward tcp:5555 tcp:8000
复制文件
可向一个设备或从一个设备中复制文件
复制一个文件或目录到设备或模拟器上:
adb push
如:
adb push test.txt /tmp/test.txt
从设备或模拟器上复制一个文件或目录
adb pull
如:
adb pull /android/lib/libwebcore.os
搜索/等待模拟器、设备实例
取得当前运行的模拟器、设备的实例列表及每个实例的状态 |
等待正在运行的设备
adb devices
adb wait-for-device
查看 Bug 报告
adb bugreport
记录无线通讯日志
无线通讯记录日志非常多,在运行时没必要记录,可以通过命令设置记录
adb shell
logcat -b radio
获取设备 ID 和序列号
adb get-product
adb get-serialno
访问数据库 SQLite3
adb shell
sqlite3
|
上一篇: Android入门教程(四)之------Android工程目录结构介绍下一篇: Android开发笔记第一篇(开放手机联盟--Open Handset Alliance)
|