作者:郭孝星

微博:郭孝星的新浪微博

邮箱:allenwells@163.com

博客:http://blog.csdn.net/allenwells

github:https://github.com/AllenWell

一 AVD管理

AVD管理相关命令例如以下所看到的:

  • android avd : 打开AVD管理器
  • android list : 列举已经安装的Android版本号和Android模拟器
  • android list avd : 列举已经安装的Android模拟器
  • android list device : 列举已经连接的Android设备
  • android create avd : 创建Android模拟器
  • android move avd : 移动或重命名Android模拟器
  • android delete avd : 删除Android模拟器
  • android update avd : 更新Android模拟器

二 SDK管理

SDK管理相关命令例如以下所看到的:

  • android sdk : 打开SDK管理器
  • android list sdk : 列举远程SDK版本号
  • android list target : 列举已经安装的Android版本号
  • android update sdk : 更新SDK

三 SD卡管理

当我们创建一个AVD时。系统会自己主动创建虚拟存储卡,假设我们想单独创建虚拟存储卡,能够使用命令mksdcard。

命令mksdcard语法格式例如以下所看到的:

mksdcard [-l label] <size> <file>
  • size:执行虚拟SD卡大小
  • file:执行保存虚拟SDka的文件镜像

举例

创建一个60MB的SD卡,并将其镜像保存到D:\sdcard.img。

mksdcard 64M D:\sdcard.img

四 设备调试

ADB(Android Debug Bridge)是有Google官方推出的调试工具,借助该工具能够管理Android设备或模拟器的状态。进行系统升级、应用管理等操作。

ADB的工作原理是监听Socket TCP5544端口的方式让IDE或DOS和Qemu进行通信。进而控制设备的状态。

4.1 AVD操作命令

1 显示系统中所有Android平台

android list targets

2 显示系统中所有AVD

android list avd

3 创建AVD

android create avd --name 名称 --target 平台编号

4 启动AVD

emulator -avd 名称 -sdcard ~/名称.img (-skin 1280x800)

5 删除AVD

android delete avd --name 名称

6 搜索模拟器/设备的实例。取得当前执行的模拟器/设备的实例的列表及每一个实例的状态

adb devices

7 获取设备的ID和序列号

adb get-product
adb get-serialno

4.2 APK操作命令

1 安装APK

adb install -r 应用程序.apk

2 缷载apk包

adb shell
cd data/app
rm apk包
exit
adb uninstall apk包的主包名
adb install -r apk包

3 删除系统应用

adb remount (又一次挂载系统分区,使系统分区又一次可写)
adb shell
cd system/app
rm *.apk

4 启动Activity

adb shell am start -n 包名/包名+类名(-n 类名,-a action,-d date,-m MIME-TYPE,-c category,-e 扩展数据等)。

5 启动SDK,文档,实例下载管理器

android

2.3 系统操作命令

1 获取模拟器中的文件

adb pull <remote> <local>

从设备或模拟器上复制一个文件或文件夹:

adb pull <source> <destination></destination></source>

比如:

adb pull /addroid/lib/libwebcore.so

2 向模拟器中写文件

adb push <local> <remote>

一个设备或从一个设备中拷贝文件, 复制一个文件或文件夹到设备或模拟器上:

adb push <source> <destination></destination></source>

比如:

adb push test.txt /tmp/test.txt

3 进入模拟器的shell模式

adb shell

4 查看adb命令帮助信息

adb help

5 在命令行中查看LOG信息

adb logcat -s 标签名

6 获取管理员权限

adb root

7 公布端口

你能够设置随意的端口号,做为主机向模拟器或设备的请求端口。

如: adb forward tcp:5555 tcp:8000。

8 查看bug报告

adb bugreport

9 记录无线通讯日志

一般来说。无线通讯的日志许多,在执行时不是必需去记录,但我们还是能够通过命令,设置记录:

adb shell
logcat -b radio

10 訪问数据库SQLite3

adb shell
sqlite3

五 项目管理

5.1 项目创建

Android项目创建相关命令例如以下所看到的:

  • android create project : 创建项目
  • android update project : 更细项目
  • android create test-project : 创建測试项目
  • android update test-project : 更新測试项目
  • android create lib-project : 创建库项目
  • android update lib-project : 更新库项目
  • android create uitest-project: 创建UI測试项目
  • android update adb : 更新ADB以支持在SDK add-ons定义的USB设

举例

创建Android工程

注意:把SDK_HOME/tools和SDK_HOME/platfrom-tools加入到系统Path里,方便开发。下面两个工具在tools文件夹下。

执行命令:

android create project --target <target-id> --name MyApp \
--path <path-to-workspace>/MyApp --activity MyActivity \
--package com.allenwells.myapp

替换 ,替换 为你想要保存项目的路径。例如以下所看到的:

android create project --target android-22 --name MyApp --path D:\workplace_studio\MyApp --activity MyActivity --package com.allenwells.myapp

命令行显示工程创建流程,例如以下图所看到的:

创建后的项目工程文件夹结构例如以下图所看到的:

5.2 资源打包

Android的资源打包工具是aapt。

经常使用语法格式例如以下所看到的:

aapt -A <附件资源路径> -S <资源路径> -M <Android应用清单文件> -I <额外附加的包> -F <目标文件路径>
  • aapt l[ist] [-v] [-a] file.{zip,jar,apk}

列出资源压缩包里的内容。

  • aapt d[ump] [–values] WHAT file.{apk} [asset [asset …]]

查看APK里的内容

badging          Print the label and icon for the app declared in APK.
permissions Print the permissions from the APK.
resources Print the resource table from the APK.
configurations Print the configurations in the APK.
xmltree Print the compiled xmls in the given assets.
xmlstrings Print the strings of the given compiled xml assets.
  • aapt p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] \

    [-0 extension [-0 extension …]] [-g tolerance] [-j jarfile] \

    [–debug-mode] [–min-sdk-version VAL] [–target-sdk-version VAL] \

    [–app-version VAL] [–app-version-name TEXT] [–custom-package VAL] \

    [–rename-manifest-package PACKAGE] \

    [–rename-instrumentation-target-package PACKAGE] \

    [–utf16] [–auto-add-overlay] \

    [–max-res-version VAL] \

    [-I base-package [-I base-package …]] \

    [-A asset-source-dir] [-G class-list-file] [-P public-definitions-file]\

    [-S resource-sources [-S resource-sources …]] \

    [-F apk-file] [-J R-file-dir] \

    [–product product1,product2,…] \

    [-c CONFIGS] [–preferred-configurations CONFIGS] \

    [raw-files-dir [raw-files-dir] …] \

    [–output-text-symbols DIR]

打包生成资源压缩包

  • aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 …]

从压缩包中删除指定文件。

  • aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 …]

向压缩包加入指定文件。

  • aapt c[runch] [-v] -S resource-sources … -C output-folder …

处理PNG资源并把处理结果保存到外部文件夹中。

  • aapt v[ersion]

打印aapt版本号。

具体选项參见:

 Modifiers:
-a print Android-specific data (resources, manifest) when listing
-c specify which configurations to include. The default is all
configurations. The value of the parameter should be a comma
separated list of configuration values. Locales should be specified
as either a language or language-region pair. Some examples:
en
port,en
port,land,en_US
If you put the special locale, zz_ZZ on the list, it will perform
pseudolocalization on the default locale, modifying all of the
strings so you can look for strings that missed the
internationalization process. For example:
port,land,zz_ZZ
-d one or more device assets to include, separated by commas
-f force overwrite of existing files
-g specify a pixel tolerance to force images to grayscale, default 0
-j specify a jar or zip file containing classes to include
-k junk path of file(s) added
-m make package directories under location specified by -J
-u update existing packages (add new, replace older, remove deleted files)
-v verbose output
-x create extending (non-application) resource IDs
-z require localization of resource attributes marked with
localization="suggested"
-A additional directory in which to find raw asset files
-G A file to output proguard options into.
-F specify the apk file to output
-I add an existing package to base include set
-J specify where to output R.java resource constant definitions
-M specify full path to AndroidManifest.xml to include in zip
-P specify where to output public resource definitions
-S directory in which to find resources. Multiple directories will be scann
ed
and the first match found (left to right) will take precedence.
-0 specifies an additional extension for which such files will not
be stored compressed in the .apk. An empty string means to not
compress any files at all.
--debug-mode
inserts android:debuggable="true" in to the application node of the
manifest, making the application debuggable even on production devices.
--min-sdk-version
inserts android:minSdkVersion in to manifest. If the version is 7 or
higher, the default encoding for resources will be in UTF-8.
--target-sdk-version
inserts android:targetSdkVersion in to manifest.
--max-res-version
ignores versioned resource directories above the given value.
--values
when used with "dump resources" also includes resource values.
--version-code
inserts android:versionCode in to manifest.
--version-name
inserts android:versionName in to manifest.
--custom-package
generates R.java into a different package.
--extra-packages
generate R.java for libraries. Separate libraries with ':'.
--generate-dependencies
generate dependency files in the same directories for R.java and resource
package
--auto-add-overlay
Automatically add resources that are only in overlays.
--preferred-configurations
Like the -c option for filtering out unneeded configurations, but
only expresses a preference. If there is no resource available with
the preferred configuration then it will not be stripped.
--rename-manifest-package
Rewrite the manifest so that its package name is the package name
given here. Relative class names (for example .Foo) will be
changed to absolute names with the old package so that the code
does not need to change.
--rename-instrumentation-target-package
Rewrite the manifest so that all of its instrumentation
components target the given package. Useful when used in
conjunction with --rename-manifest-package to fix tests against
a package that has been renamed.
--product
Specifies which variant to choose for strings that have
product variants
--utf16
changes default encoding for resources to UTF-16. Only useful when API
level is set to 7 or higher where the default encoding is UTF-8.
--non-constant-id
Make the resources ID non constant. This is required to make an R java cl
ass
that does not contain the final value but is used to make reusable compil
ed
libraries that need to access resources.
--error-on-failed-insert
Forces aapt to return an error if it fails to insert values into the mani
fest
with --debug-mode, --min-sdk-version, --target-sdk-version --version-code and --version-name.
Insertion typically fails if the manifest already defines the attribute.
--output-text-symbols
Generates a text file containing the resource symbols of the R class in t
he
specified folder.
--ignore-assets
Assets to be ignored. Default pattern is:
!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~

举例

将当前文件夹下assets子文件夹、res子文件夹、AndroidManifest.xml文件都打包到bin\resapk资源包中

aapt -A assets -S res -M AndroidManifest.xml -I D:\my.jar -F bin/resapk

5.3 项目编译

Android虚拟机并不直接执行Java的.class文件,它通过DX工具打包.class文件后执行。

DX工具用于将Android应用的.class文件转换为.dex文件。

dx命令格式例如以下所看到的:

dx --dex [--dump-to=<file>] [--core-library] [<file>.class | <file>.{zip,jar,apk} | <directory>}

举例

将D:\myproject\bin文件夹下的所有二进制文件转换为D:\文件夹下的my.dex文件。

dex -dex --dump-to=D:\my.dex --core-library D:\myproject\bin

5.4 应用签名

Android应用的签名工具是jarsigner。签名之前我们须要创建一个keystore库。

5.4.1 生成keystore库

keytool是密钥和证书管理工具。

keytool命令选项例如以下所看到的:

  • -alias: 生成证书的别名
  • -keyalg: 生成证书的算法
  • -validity: 生成证书的有效期
  • -keystore: 生成证书的具体路径
  • -certreq: 生成证书请求
  • -changealias: 更改条目的别名
  • -delete: 删除条目
  • -exportcert: 导出证书
  • -genkeypair: 生成密钥对
  • -genseckey: 生成密钥
  • -gencert: 依据证书请求生成证书
  • -importcert: 导入证书或证书链
  • -importpass: 导入口令
  • -importkeystore: 从其它密钥库导入一个或所有条目
  • -keypasswd: 更改条目的密钥口令
  • -list: 列出密钥库中的条目
  • -printcert: 打印证书内容
  • -printcertreq: 打印证书请求的内容
  • -printcrl: 打印 CRL 文件的内容
  • -storepasswd: 更改密钥库的存储口令

举例

创建一个名为my.keystore的keystore库

keytool -genkeypair -alias my.keystore -keyalg RSA -validity 400 -keystore my.keystore

命令执行后会提示我们填写一系列的东西,例如以下图所看到的:

填写完毕后。能够发如今当前文件夹下生成了my.keystore文件,例如以下图所看到的:

5.4.2 用keystore库给应用签名

jarsigner:应用签名工具

jarsigner命令使用方法例如以下所看到的:

jarsigner [选项] jar-file 别名
jarsigner -verify [选项] jar-file [别名...]

jarsigner命令相关选项例如以下所看到的:

  • [-keystore ]: 密钥库位置
  • [-storepass <口令>]: 用于密钥库完整性的口令
  • [-storetype <类型>]: 密钥库类型
  • [-keypass <口令>]: 私有密钥的口令 (假设不同)
  • [-certchain <文件>]: 替代证书链文件的名称
  • [-sigfile <文件>]: .SF/.DSA 文件的名称
  • [-signedjar <文件>]: 已签名的 JAR 文件的名称
  • [-digestalg <算法>]: 摘要算法的名称
  • [-sigalg <算法>]: 签名算法的名称
  • [-verify]: 验证已签名的 JAR 文件
  • [-verbose[:suboptions]]: 签名/验证时输出具体信息。

    选项能够是 all, grouped 或 summary

  • [-certs]: 输出具体信息和验证时显示证书
  • [-tsa ]: 时间戳颁发机构的位置
  • [-tsacert <别名>]: 时间戳颁发机构的公共密钥证书
  • [-tsapolicyid ]: 时间戳颁发机构的 TSAPolicyID
  • [-altsigner <类>]: 替代的签名机制的类名
  • [-altsignerpath <路径列表>]: 替代的签名机制的位置
  • [-internalsf]: 在签名块内包括 .SF 文件
  • [-sectionsonly]: 不计算整个清单的散列
  • [-protected]: 密钥库具有受保护验证路径
  • [-providerName <名称>]: 提供方名称
  • [-providerClass <类>: 加密服务提供方的名称
  • [-providerArg <參数>]]… 主类文件和构造器參数
  • [-strict]: 将警告视为错误

举例

用my.keystore给my.apk签名

jarsigner -verbose -keystore my.keystore -signedjar my_signed.apk  my.apk my.keystore
  • -verbose:执定生成具体输出
  • -keystore:指定生成数字证书的存储路径
  • -signedjar:该选项后的三个參数分别为:签名后的APK、未签名的APK和数字证书的别名。

签名流程例如以下图所看到的:

【Android应用开发技术:基础构建】命令行下的Android应用开发的更多相关文章

  1. Linux命令行下编译Android NDK的示例代码

    这几天琢磨写一个Android的Runtime用来加速HTML5 Canvas,让GameBuilder+CanTK 不但开发速度快,运行速度也能接近原生应用.所以花了点时间研究 Android ND ...

  2. iOS开发——源代码管理——svn 命令行下常用的几个命令

    1.将文件checkout到本地目录    svn checkout path(path是服务器上的目录)    例如:svn checkout svn://192.168.1.1/pro/domai ...

  3. JavaWeb开发技术基础概念回顾篇

    JavaWeb开发技术基础概念回顾篇 第一章 动态网页开发技术概述 1.JSP技术:JSP是Java Server Page的缩写,指的是基于Java服务器端动态网页. 2.JSP的运行原理:当用户第 ...

  4. kvm--virsh命令行下管理虚拟机

    virsh 既有命令行模式,也有交互模式,在命令行直接输入 virsh 就进入交互模式, virsh 后面跟命令参数,则是命令行模式: (1)基础操作 --- 命令行下管理虚拟机 virsh list ...

  5. [编译] 6、开源两个简单且有用的安卓APP命令行开发工具和nRF51822命令行开发工具

    星期四, 27. 九月 2018 12:00上午 - BEAUTIFULZZZZ 一.前言 前几天给大家介绍了如何手动搭建安卓APP命令行开发环境和nRF51822命令行开发环境,中秋这几天我把上面篇 ...

  6. Go通过cobra快速构建命令行应用

    来自jetbrains Go 语言现状调查报告 显示:在go开发者中使用go开发实用小程序的比例为31%仅次于web,go得益于跨平台.无依赖的特性,用来编写命令行或系统管理这类小程序非常不错. 本文 ...

  7. #WPF的3D开发技术基础梳理

    原文:#WPF的3D开发技术基础梳理 自学WPF已经有半年有余了,一遍用,一边学.但是一直没有去触摸WPF的3D开发相关技术,因为总觉得在内心是一座大山,觉得自己没有能力去逾越.最近因为一个项目的相关 ...

  8. 教你用Cobra开发类似docker的命令行

    目录 前言 一.安装 二.初始化应用 gomod初始化 创建入口文件cmd/root.go 创建主程序main.go 三.生成Command 创建hello子命令 创建version子命令 四.如何设 ...

  9. Apache Commons CLI官方文档翻译 —— 快速构建命令行启动模式

    昨天通过几个小程序以及Hangout源码学习了CLI的基本使用,今天就来尝试翻译一下CLI的官方使用手册. 下面将会通过几个部分简单的介绍CLI在应用中的使用场景. 昨天已经联系过几个基本的命令行参数 ...

随机推荐

  1. 解决ORA-28002: 密码7天之后过期办法

    https://www.douban.com/group/topic/46177516/ https://yq.aliyun.com/ziliao/42484 http://blog.csdn.net ...

  2. WinServer-IIS-MIME类型

    自定义类型的处理流程 1.浏览器问服务器,这是什么类型的文件 2.服务器告诉浏览器这是什么类型的文件(如果不告诉,那么浏览器就会下载相应文件) 3.浏览器告诉windows注册表这是什么类型的文件 4 ...

  3. Tomcat远程代码执行漏洞(CVE-2017-12615)修复

    一.漏洞介绍 2017年9月19日,Apache Tomcat官方确认并修复了两个高危漏洞,其中就有Tomcat远程代码执行漏洞,当存在漏洞的Tomcat运行在Windwos主机上,且启用了HTTP ...

  4. HTML---经常使用标签总结与实践

    什么是HTML? 超文本标记语言,标准通用标记语言下的一个应用.    "超文本"就是指页面内能够包括图片.链接,甚至音乐.程序等非文字元素. 超文本标记语言的结构包含" ...

  5. 【SPOJ-GSHOP】Rama and Friends【贪心】【细节】

    题意: 给出n个非严格递增的整数(可能有负数),必须操作k次.每次能够把当中一个数变为它的相反数,使得终于的数列和最大. 输出这个最大和. 考验怎样出坑数据卡自己的程序... #include < ...

  6. Android实现天气预报温度/气温折线趋势图

     Android实现天气预报温度/气温折线趋势图 天气预报的APP应用中,难免会遇到绘制天气温度/气温,等关于数据趋势的折线或者曲线图,这类关于气温/温度的折线图,通常会有两条线.一条是高温线,一 ...

  7. offsetLeft,Left,clientLeft具体解释

      假设 obj 为某个 HTML 控件. obj.offsetTop 指 obj 相对于版面或由 offsetParent 属性指定的父坐标的计算上側位置,整型,单位像素. obj.offsetLe ...

  8. &quot;浪潮杯&quot;第六届ACM山东省省赛山科场总结

    从空间拷过来的.尽管已经过去一个月了.记忆犹新 也算是又一次拾起这个blog Just begin 看着一群群大牛还有队友男神的省赛总结都出了 我最终也耐不住寂寞 来做个流水账抒抒情好了 第一次省赛 ...

  9. 详解JSP九个内置对象

    [JSP]☆★之详解九个内置对象       在web开发中,为方便开发者,JSP定义了一些由JSP容器实现和管理的内置对象,这些对象可以直接被开发者使用,而不需要再对其进行实例化!本文详解,JSP2 ...

  10. [jzoj 5926] [NOIP2018模拟10.25] naive 的图 解题报告(kruskal重构树+二维数点)

    题目链接: https://jzoj.net/senior/#main/show/5926 题目: 题解: 显然最小的最大路径在最小生成树上(最小生成树=最小瓶颈生成树) 于是我们建出kruskal重 ...