移动平台应用软件开发 Android 介绍 主讲 : 张齐勋 zhangqx@ss.pku.edu.cn 移动平台应用软件开发 课程建设小组 北京大学 二零一七年秋北京
Android是什么 Android不仅仅是一个操作系统 它更是一个完整的软件框 架 Android基于Linux内核 2005年Google公司收购了Android公司 Google公司选择使用Apache许可证开放Android源码 当前最新的版本为Android 运行在手机 平板 电视 手表上
Android 主要发行版本 版本号 代号 Linux 版本 API 级别 发行时间 1.0 Wind Up Robot 发条机器人 未知 1 2008 年 9 月 23 日 1.5 Cupcake 纸杯蛋糕 2.6.27 3 2009 年 4 月 17 日 1.6 Donut 甜甜圈 2.6.29 4 2009 年 9 月 15 日 2.2 Froyo 冻酸奶 2.6.32 8 2010 年 5 月 20 日 2.3 Gingerbread 姜饼 2.6.35 9 2010 年 12 月 7 日 3.0 Honeycomb 蜂巢 2.6.36 11 2011 年 2 月 3 日 4.0 Ice Cream Sandwich 雪糕三明治 4.1/4.2/4.3 Jelly Bean 果冻豆 3.0.X 14 2011 年 10 月 19 日 3.0.X/3.4.X 16/17/18 2012 年 6 月 28 日 4.4 KitKat 奇巧 3.10 19 2013 年 9 月 4 日 5.0/5.1 Lollipop 棒棒糖 3.14 21/22 2014 年 10 月 15 日 6.0 Marshmallow 棉花糖 3.4+ 23 2015 年 5 月 28 日 6.X Android N 24 2016 年 5 月 19 日
Android 各版本分布情况 (2015)
Android 各版本分布情况 (2016)
Linux 系统介绍 Linux history Creator: LinusTorvalds, Finland Just for fun Related to Minix Open source
Linux内核 Linux的官方网站www.kernel.org
Linux 系统体系结构
Android 系统架构
Android 包含一些 C/C++ 库, 这些库能被 Android 系统中不同的组件使用 它们通过 Android 应用程序框架为开发者提供服务 以下是一些核心库 : 系统 C 库 一个定制的标准 C 系统函数库 (libc) 媒体库 该库支持多种常用的音频 视频格式回放和录制, 同时支持静态图象文件 编码格式包括 MPEG4 H.264 MP3 AAC AMR JPG PNG Surface Manager 对显示子系统的管理 webkit 一个 Web 浏览器引擎, 用来支持 Android 浏览器和一个可嵌入的 Web 视图 SGL 底层的 2D 图形引擎 3D libraries 基于 OpenGL ES APIs 实现, 该库可以使用硬件 3D 加速, 或者使用高度优化的 3D 软加速 FreeType 位图 (bitmap) 和矢量 (vector) 字体显示 SQLite 一个对于所有应用程序可用, 功能强大的轻型关系型数据库引擎
Android 应用开发环境 JDK IDE Eclipse Eclipse plug-in - ADT Software Development Kit (SDK) Android Virtual Devices(AVD) Manager Android Emulator Dalvik Debug Monitor Services(DDMS) Android Debug Bridge(ADB)
开发环境安装 安装 JDK 安装 Eclipse
SDK SDK 中一般包含 Debugger Libraries Emulator Documentation, sample code 等 下载并安装 SDK: http://developer.android.com/sdk/index.html It includes only the core SDK tools, which you can use to download the rest of the SDK packages. 还需要下载其他软件包 : SDK Tools Required. SDK Platform-tools Required. SDK Platform Required. Android Support Library Required.
http://developer.android.com/sd k/installing/installing-adt.html 可在线下载也可离线安装
配置 ADT 启动 Eclipse 选择 Windwos > Preference 选择 Android 指定 SDK Location 路径中包含中文 空格 (x86) 等, 均有可能出错
AVD
Android Device Chooser
DDMS
ADB 位于 SDK 中的 platform-tools 目录下 可以将该目录加入到 PATH 路径中
src 中是 Java 程序 Android 应用程序框架 gen 中有一个自动生成的文件 R.java, 该文件不能修改, 其中存放的是 res 资源 ID res 中是各种资源, 包括图像 布局和字符串等, 他们都有惟一一个 ID assets 也可放资源, 但不会产生 ID AndroidManifest.xml 是配置文件
源程序 ( JAVA ) package com.android.hello; import android.app.activity; import android.os.bundle; public class HelloAndroidActivity extends Activity { /** Called when the activity is first created. */ @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); } }
R.java public final class R { public static final class attr { } public static final class drawable { public static final int ic_launcher=0x7f020000; } public static final class id { public static final int togglebutton1=0x7f050000; } public static final class layout { public static final int main=0x7f030000; } public static final class string { public static final int app_name=0x7f040001; public static final int hello=0x7f040000; } }
main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>
strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">hello World, HelloAndroidActivity!</string> <string name="app_name">helloandroid</string> </resources>
AndroidManifest.xml
AndroidManifest.xml 当 Android 启动一个应用程序组件之前, 它必须知道那个组件是存在的 应用程序会在 (AndroidManifest.xml) 一个清单文件中声明它的组件 这个文件会被打包到 Android 的应用程序 apk 中
Android Studio Google 官方发布的 IDE 开发工具 取代原有的基于 Eclipse 的开发环境 基于 IntelliJ IDEA 开源版本
Ø 将 java 代码和资源文件 ( 图片 布局文件等 ) 全部归结为 src Ø 在 src 目录下有一个 main 的分组, 同时划分出 java 和 res 两个组 Ø res 和 Eclipse 下的结构一样 Ø java 下就是源码的包和类文件 ; Ø AndroidManifest 文件也在 src 目录中 目录结构
Android 自带的控件
Android 程序打包 Java code javac Byte code.java.class dx Dalvik exe classes.dex aapt Byte code Other.class files <xml> AndroidManifest.x ml <str > Resources
Q&A 本讲结束!