Andorid aapt 命令~图解

来源:互联网 发布:oracle数据库迁移 编辑:程序博客网 时间:2024/06/06 20:33

转自:http://blog.csdn.net/jiangshide/article/details/7482605

在Android开发过程中,我们难免会涉及到WEB方面需求,如果想对WEB中所有APK各自的相关基本信息进行扫描与了解,在这里我们可以对其在android中集成的aapt命令进行剖析,首先,我们在命令行中输入:aapt help,得到如下详细列表显示:






OK,以上是通过HELP得到的相关帮助说明,你可以更具其列表显示来进行相关操作,我就简单引些例子吧:

首先我开个头给翻译下:

Android Asset Packaging Tool
Android 资源包工具
Vsage:(用法)
aapt l[ist] [-v] [-a] file.{zip,jar,apk}
List contents of Zip-compatible archive.
兼容的ZIP归档的列表内容
aapt d[ump] [--values] WHAT file.{apk} [asset [asset ...]]
badging  Print the label and icon for the app declared in APK.
徽章 为声明的APK打印标签与图标
permissions Print the permisssions from the APK.
权限 打印来自于APK中的权限
resources  Print the resource table from the APK.
资源 打印来自于APK的资源表
configurations Print the configurations in the APK.
配置 打印来自于APK声明的配置文件
xmltree  Print the compiled xmls in the given assets.
XML树 打印给定的资源中编译后的XML
xmlstrings Print the strings of the given compiled xml assets.
XML字符串  打印给定的资源文件中编译后的字符串

appt 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] \
  [-o] \
  [raw-files-dir [raw-files-dir] ...]
Package the android resources.It will read assets and resources that are
supplied with the -M -A -S or raw-files-dir arguments.The -J -P -F and -R
options control with files are output.

上面这段好理解,就是aapt对应APP包的相关信息,如DEBUG模式,最小版本,目标SDK版本APP名称与版本以及编码等信息的输出.

appt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]
Delete specified files from Zip-cpmpatible archive.

这是指定移出来自归档的某个文件
appt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]
Add specified files to Zip-compatible archive.

指定某归档进行添加文件
aapt c[runch] [-v] -S resource-sources ... -C output-folder ...
Do PNG preprocessing and store the results in output folder.

对PNG格式处理并进行存储然后对其结果输出到文件夹中
aapt v[ersion] 
Print program version.

 打印应用程序的版本

Modifiers:
-a print Android-specific data (resources,manifest) when listing

打印androdi指定l列出来的数据,如resource与manifest的资源数据
-c specify which configurations to include.The default is all

configurations.The value of the parameter should be a comma
separated list of configuration value.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
pseudolocalozation on the default locale,modifying all of the
strings so you can look for strings that missed the
internationalization process.Forexample:
port,land,zz_ZZ
-d one or more device assets to include,separated by commas

一个或多个资源文件
-f force overwite 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
-o create overlay package (ie only resource; expects <overlay-package> in manifest)
-u upate existing package (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 resurce constant definitions
-M specify full path to AndroidManifest.xml to incliude in zip
-P specify where to output public resource definitions
-S directory in which to find resources.Multiple directories will be scanned
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 int 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:versionName in to manifest.
--version-name
inserts android:versionName in to manifest.
--custom-package
generates R.java into a deferent 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 resource that are only in overlays.
--preferred-configurations
Like the -c option for filtering out unneeded configurations,but only expresses a 
prefference,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 packeg name is the package name given here.
Relative calss name (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 


congunction 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
--utf166
changes default encoding for resources to UTF-16.Only userful 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 class that does not contain the final value but 


is used to make reusable compiled libraries that need to access resource. 

以上是对最上面的相关参数值进行解释,没事也多看看吧,这些不需要你去记住,你只需要知道有这么回事即可,就简单那举个例子吧:

现在我们有个需求就是想把一个已经存在的APK的相关包与资源路径显示出来,我们应该这么做呢,看,我们根据以上信息可以得到如下命令:

aapt l -a xxx.apk > xxx.txt

xxx.apk指定哪个apk文件,xxx.txt:把获得的信息输出到这个文件,并保存于当前目录中,如图:


生成的文件如下:



获得文件信息如下:



,好了,别的就不多说了.需要获得什么信息,你可以带入相关参数即可

搭建好android开发环境后,

cmd进入命令终端,
执行 aapt dump badging  yours.apk
就会看到对应的包名,Activity名

0 0