标签:
作者:郭孝星
微博:郭孝星的新浪微博
邮箱:allenwells@163.com
博客:http://blog.csdn.net/allenwells
github:https://github.com/AllenWell
AVD管理相关命令如下所示:
SDK管理相关命令如下所示:
当我们创建一个AVD时,系统会自动创建虚拟存储卡,如果我们想单独创建虚拟存储卡,可以使用命令mksdcard。
命令mksdcard语法格式如下所示:
mksdcard [-l label] <size> <file>
举例
创建一个60MB的SD卡,并将其镜像保存到D:\sdcard.img。
mksdcard 64M D:\sdcard.img
ADB(Android Debug Bridge)是有Google官方推出的调试工具,借助该工具可以管理Android设备或模拟器的状态,进行系统升级、应用管理等操作。ADB的工作原理是监听Socket TCP5544端口的方式让IDE或DOS和Qemu进行通信,进而控制设备的状态。
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
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
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
Android项目创建相关命令如下所示:
举例
创建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
命令行显示工程创建流程,如下图所示:
创建后的项目工程目录结构如下图所示:
Android的资源打包工具是aapt。
常用语法格式如下所示:
aapt -A <附件资源路径> -S <资源路径> -M <Android应用清单文件> -I <额外附加的包> -F <目标文件路径>
列出资源压缩包里的内容。
查看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.
打包生成资源压缩包
从压缩包中删除指定文件。
向压缩包添加指定文件。
处理PNG资源并把处理结果保存到外部文件夹中。
打印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
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
Android应用的签名工具是jarsigner,签名之前我们需要创建一个keystore库。
keytool是密钥和证书管理工具。
keytool命令选项如下所示:
举例
创建一个名为my.keystore的keystore库
keytool -genkeypair -alias my.keystore -keyalg RSA -validity 400 -keystore my.keystore
命令执行后会提示我们填写一系列的东西,如下图所示:
填写完成后,可以发现在当前目录下生成了my.keystore文件,如下图所示:
jarsigner:应用签名工具
jarsigner命令用法如下所示:
jarsigner [选项] jar-file 别名
jarsigner -verify [选项] jar-file [别名...]
jarsigner命令相关选项如下所示:
举例
用my.keystore给my.apk签名
jarsigner -verbose -keystore my.keystore -signedjar my_signed.apk my.apk my.keystore
签名流程如下图所示:
版权声明:当我们认真的去做一件事的时候,就能发现其中的无穷乐趣,丰富多彩的技术宛如路上的风景,边走边欣赏。
【Android应用开发技术:基础构建】命令行下的Android应用开发
标签:
原文地址:http://blog.csdn.net/allenwells/article/details/47663541