《Android/OPhone开发完全讲义》连载(4):Android SDK中常用命令行工具(二)

简介: 本文为原创,如需转载,请注明作者和出处,谢谢! 本文为新书《Android/OPhone 开发完全讲义》的内容连载。《Android/OPhone开发完全讲义》一书现已出版,敬请关注。

本文为原创,如需转载,请注明作者和出处,谢谢!

本文为新书《Android/OPhone 开发完全讲义》的内容连载。《Android/OPhone开发完全讲义》一书现已出版,敬请关注。

购 买:互动网(china- pub)

《Android/OPhone开发完全讲义》目录


源代码下载



  <!-- /* Font Definitions */ &#64;font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} &#64;font-face {font-family:黑体; panose-1:2 1 6 9 6 1 1 1 1 1; mso-font-alt:SimHei; mso-font-charset:134; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-2147482945 953122042 22 0 262145 0;} &#64;font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 415 0;} &#64;font-face {font-family:"/&#64;宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} &#64;font-face {font-family:"/&#64;黑体"; panose-1:2 1 6 9 6 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-2147482945 953122042 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; line-height:15.7pt; mso-pagination:none; mso-layout-grid-align:none; font-size:10.5pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:宋体;} h3 {mso-style-name:"标题 3/,/(分步/)/,/(小节/)"; mso-style-unhide:no; mso-style-qformat:yes; mso-style-link:"标题 3 Char"; mso-style-next:正文; margin-top:15.0pt; margin-right:0cm; margin-bottom:15.0pt; margin-left:0cm; text-align:justify; text-justify:inter-ideograph; line-height:15.7pt; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:3; mso-layout-grid-align:none; font-size:13.0pt; mso-bidi-font-size:10.5pt; font-family:"Arial","sans-serif"; mso-fareast-font-family:黑体; font-weight:normal;} span.3Char {mso-style-name:"标题 3 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 3/,/(分步/)/,/(小节/)"; mso-ansi-font-size:13.0pt; mso-bidi-font-size:10.5pt; font-family:"Arial","sans-serif"; mso-ascii-font-family:Arial; mso-fareast-font-family:黑体; mso-hansi-font-family:Arial; mso-bidi-font-family:Arial;} p.a, li.a, div.a {mso-style-name:编程步骤; mso-style-unhide:no; mso-style-link:"编程步骤 Char"; margin-top:0cm; margin-right:0cm; margin-bottom:0cm; margin-left:21.0pt; margin-bottom:.0001pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:0cm; mso-para-margin-left:2.0gd; mso-para-margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; line-height:13.0pt; mso-pagination:none; layout-grid-mode:char; background:#E0E0E0; mso-layout-grid-align:none; font-size:9.0pt; font-family:"Arial","sans-serif"; mso-fareast-font-family:黑体;} span.Char {mso-style-name:"编程步骤 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:编程步骤; mso-ansi-font-size:9.0pt; mso-bidi-font-size:9.0pt; font-family:"Arial","sans-serif"; mso-ascii-font-family:Arial; mso-fareast-font-family:黑体; mso-hansi-font-family:Arial; mso-bidi-font-family:Arial; background:#E0E0E0;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ &#64;page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} &#64;page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} -->  

上一篇:Android SDK中常用命令行工具(一)

一、
    P C与模拟器或真机交换文件(adb pull和adb push)

在开发阶段或其他原因,经常需要将PC上的文件复制到模拟器或真机上,或将模拟机和真机上的文件复制到PC上。使用adb pull和adb push命令可以很容易完成这个工作。例如,下面的命令将真机的SD卡根目录下的camera.jpg文件复制到PC的当前目录,取名为picture.jpg。又把picture.jpg文件复制到真机的SD卡根目录,取名为abc.jpg。

从真机上复制文件到PC

adb -s HT9BYL904399 pull /sdcard/camera.jpg picture.jpg

从PC复制到文件到真机

adb -s HT9BYL904399 push picture.jpg /sdcard/abc.jpg

如果读者安装了ADT,可以通过DDMS透视图的【File Explorer】视图右上方的几个按钮方便地从模拟器或真机上导入、导出和删除文件。

二、 Shell命令

由于Android是基于Linux内核的操作系统。因此,在Android上可以执行Shell命令。虽然在手机上提供了可以输入命令的Shell程序,但在手机上输入程序实在是不方便。为了更方便地在模拟器或手机上执行Shell命令。可以使用如下的命令在PC上进入Shell控制台。

adb -s HT9BYL904399 shell

Shell控制台的提示符是一个井号(#)。进入Shell后,输入cd system/bin命令,再输入ls命令,可以看到当前Android系统支持的命令文件,如图1所示。读者可以根据实际情况使用相应的命令。


                       图1    <!-- /* Font Definitions */ &#64;font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} &#64;font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 415 0;} &#64;font-face {font-family:"/&#64;宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; line-height:15.7pt; mso-pagination:none; mso-layout-grid-align:none; font-size:10.5pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:宋体;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ &#64;page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} &#64;page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} -->  Shell控制台

  <!-- /* Font Definitions */ &#64;font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} &#64;font-face {font-family:黑体; panose-1:2 1 6 9 6 1 1 1 1 1; mso-font-alt:SimHei; mso-font-charset:134; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-2147482945 953122042 22 0 262145 0;} &#64;font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 415 0;} &#64;font-face {font-family:"/&#64;宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} &#64;font-face {font-family:"/&#64;黑体"; panose-1:2 1 6 9 6 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-2147482945 953122042 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; line-height:15.7pt; mso-pagination:none; mso-layout-grid-align:none; font-size:10.5pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:宋体;} h3 {mso-style-name:"标题 3/,/(分步/)/,/(小节/)"; mso-style-unhide:no; mso-style-qformat:yes; mso-style-link:"标题 3 Char"; mso-style-next:正文; margin-top:15.0pt; margin-right:0cm; margin-bottom:15.0pt; margin-left:0cm; text-align:justify; text-justify:inter-ideograph; line-height:15.7pt; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:3; mso-layout-grid-align:none; font-size:13.0pt; mso-bidi-font-size:10.5pt; font-family:"Arial","sans-serif"; mso-fareast-font-family:黑体; font-weight:normal;} span.3Char {mso-style-name:"标题 3 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"标题 3/,/(分步/)/,/(小节/)"; mso-ansi-font-size:13.0pt; mso-bidi-font-size:10.5pt; font-family:"Arial","sans-serif"; mso-ascii-font-family:Arial; mso-fareast-font-family:黑体; mso-hansi-font-family:Arial; mso-bidi-font-family:Arial;} p.a, li.a, div.a {mso-style-name:编程步骤; mso-style-unhide:no; mso-style-link:"编程步骤 Char"; margin-top:0cm; margin-right:0cm; margin-bottom:0cm; margin-left:21.0pt; margin-bottom:.0001pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:0cm; mso-para-margin-left:2.0gd; mso-para-margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; line-height:13.0pt; mso-pagination:none; layout-grid-mode:char; background:#E0E0E0; mso-layout-grid-align:none; font-size:9.0pt; font-family:"Arial","sans-serif"; mso-fareast-font-family:黑体;} span.Char {mso-style-name:"编程步骤 Char"; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:编程步骤; mso-ansi-font-size:9.0pt; mso-bidi-font-size:9.0pt; font-family:"Arial","sans-serif"; mso-ascii-font-family:Arial; mso-fareast-font-family:黑体; mso-hansi-font-family:Arial; mso-bidi-font-family:Arial; background:#E0E0E0;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ &#64;page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} &#64;page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} -->  

三、 创建、删除和浏览AVD设备(android)

在这里将介绍直接使用android命令来建立和删除AVD设备。建立AVD设备的命令如下:

android create avd -n myandroid1.5 -t 2

其中myandroid1.5表示AVD设备的名称,该名称可以任意设置,但不能和其他AVD设备冲突。-t 2中的2指建立Android 1.5的AVD设备。1表示Android 1.1的AVD设备。以此类推。目前最新的Android 2.1应使用-t 6来建立AVD设备。在执行完上面的命令后,会输出如下的信息来询问是否继续定制AVD设备。

Android 1.5 is a basic Android platform.

Do you wish to create a custom hardware profile [no]

如果读者不想继续定制AVD设备,直接按回车即可。如果想定制AVD设备,输入y,然后按回车。系统会按步提示该如何设置。中括号内是默认值,如果某个设置项需要保留默认值,直接按回车即可。如果读者使用的是Windows XP,默认情况下AVD设备文件放在如下的目录。

C:/Documents and Settings/Administrator/.android/avd

如果想改变AVD设备文件的默认存储路径,可以使用-p命令行参数,命令如下:

android create avd -n myandroid1.5 -t 2 -p d:/my/avd

删除AVD设备可以使用如下的命令。

android delete avd -n myandroid1.5

通过下面的命令可以列出所有的AVD设备。

android list avds





 

 






 var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-16915591-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();

目录
相关文章
|
移动开发 前端开发 Android开发
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
2059 12
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
移动开发 JavaScript 应用服务中间件
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
1302 5
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
移动开发 Rust JavaScript
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
1363 4
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
开发工具 Android开发
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
1135 11
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
|
移动开发 Android开发
【03】建立隐私关于等相关页面和内容-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【03】建立隐私关于等相关页面和内容-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
625 0
|
Java 开发工具 Maven
【01】完整的安卓二次商业实战-详细的初级步骤同步项目和gradle配置以及开发思路-优雅草伊凡
【01】完整的安卓二次商业实战-详细的初级步骤同步项目和gradle配置以及开发思路-优雅草伊凡
1621 6
|
安全 数据库 Android开发
在Android开发中实现两个Intent跳转及数据交换的方法
总结上述内容,在Android开发中,Intent不仅是活动跳转的桥梁,也是两个活动之间进行数据交换的媒介。运用Intent传递数据时需注意数据类型、传输大小限制以及安全性问题的处理,以确保应用的健壯性和安全性。
836 11
|
安全 Java Android开发
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡
618 0
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡
|
移动开发 Java 编译器
Kotlin与Jetpack Compose:Android开发生态的演进与架构思考
本文从资深Android工程师视角深入分析Kotlin与Jetpack Compose在Android系统中的技术定位。Kotlin通过空安全、协程等特性解决了Java在移动开发中的痛点,成为Android官方首选语言。Jetpack Compose则引入声明式UI范式,通过重组机制实现高效UI更新。两者结合不仅提升开发效率,更为跨平台战略和现代架构模式提供技术基础,代表了Android开发生态的根本性演进。
706 0
|
JavaScript 前端开发 Java
[Android][Framework]系统jar包,sdk的制作及引用
[Android][Framework]系统jar包,sdk的制作及引用
739 0