来自:http://mmmyddd.freeshell.net/blog.cgi/Computer/Android/aapt-decompress-apk

AAPT 工具介绍

下面是取自"http://www.androidcn.net/wiki/index.php/Reference/aapt"的介绍

aapt stands for Android Asset Packaging Tool and is included in the tools/ directory of the SDK. This tool allows you to view, create, and update Zip-compatible archives (zip, jar, apk). It can also compile resources into binary assets.

aapt即Android Asset Packaging Tool , 在SDK的tools/目录下. 该工具可以查看, 创建, 更新ZIP格式的文档附件(zip, jar, apk). 也可将资源文件编译成二进制文件.

Though you probably won't often use aapt directly, build scripts and IDE plugins can utilize this tool to package the apk file that constitutes an Android application.

尽管你可能没有直接使用过aapt工具, 但是build scripts和IDE插件会使用这个工具打包apk文件构成一个Android 应用程序.

For more usage details, open a terminal, go to the tools/ directory, and run the command:

获取更多的实用信息, 请打开终端控制台, 到tools/目录下, 执行命令:

Linux or Mac OS X:

./aapt

Windows:

aapt.exe

AAPT 的帮助信息

执行上述命令,会在控制台打出相应aapt的信息:

Android Asset Packaging Tool

Usage:
aapt l[ist] [-v] [-a] file.{zip,jar,apk}
List contents of Zip-compatible archive. aapt d[ump] WHAT file.{apk} [asset [asset ...]]
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] [-f][-u][-m][-v][-x][-M AndroidManifest.xml] /
[-0 extension [-0 extension ...]] /
[-I base-package [-I base-package ...]] /
[-A asset-source-dir] [-P public-definitions-file] /
[-S resource-sources] [-F apk-file] [-J R-file-dir] /
[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 which files are output. aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]
Delete specified files from Zip-compatible archive. aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]
Add specified files to Zip-compatible archive. aapt v[ersion]
Print program version. 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
-j specify a jar or zip file containing classes to include
-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
-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
-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.

根据以上帮助信息,用aapt可以使用以下操作:

查看AAPT的版本

 ./aapt v

得到当前工具的版本:

Android Asset Packaging Tool, v0.2

使用AAPT列出资源包(.apk)文件列表

 aapt l[ist] [-v] [-a] file.{zip,jar,apk}
List contents of Zip-compatible archive.

可以用命令查看系统资源包的内容:

./aapt l framework-res.apk
META-INF/MANIFEST.MF
META-INF/CERT.SF
META-INF/CERT.RSA
AndroidManifest.xml
assets/images/android_320x480.png
assets/images/boot_robot.png
assets/images/boot_robot_glow.png ... assets/webkit/youtube.html
assets/webkit/youtube.png
res/anim/accelerate_decelerate_interpolator.xml
res/anim/accelerate_interpolator.xml
res/anim/app_starting_exit.xml ... res/raw-de/loaderror.html
res/raw-de/nodomain.html
res/raw/fallbackring.ogg
res/raw/loaderror.html
res/raw/nodomain.html
res/xml-en/autotext.xml
res/xml/apns.xml
res/xml/autotext.xml
res/xml/preferred_time_zones.xml
res/xml/time_zones_by_country.xml
resources.arsc

如果采用-v选项,会将所有文件的详细信息打印出来:

Archive:  framework-res.apk
Length Method Size Ratio Date Time CRC-32 Name
-------- ------ ------- ----- ---- ---- ------ ----
76217 Deflate 25576 66% 04-16-08 07:40 3b7140fa META-INF/MANIFEST.MF
76259 Deflate 25706 66% 04-16-08 07:40 a21d76be META-INF/CERT.SF
1714 Deflate 1156 33% 04-16-08 07:40 ca66d55e META-INF/CERT.RSA
31768 Deflate 5556 83% 01-16-09 12:04 8c137ee8 AndroidManifest.xml
3098 Stored 3098 0% 01-15-09 23:16 ed1132c9 assets/images/android_320x480.png
1001 Stored 1001 0% 01-15-09 23:16 c53ad035 assets/images/boot_robot.png
2083 Stored 2083 0% 01-15-09 23:16 12acc29d assets/images/boot_robot_glow.png ... ... 340 Deflate 155 54% 01-16-09 12:04 cc2ad7f2 res/anim/accelerate_decelerate_interpolator.xml
368 Deflate 179 51% 01-16-09 12:04 c94b9323 res/anim/accelerate_interpolator.xml
568 Deflate 260 54% 01-16-09 12:04 e0972304 res/anim/app_starting_exit.xml ... ... 605 Deflate 296 51% 01-15-09 23:16 88710568 res/raw-de/loaderror.html
996 Deflate 471 53% 01-15-09 23:16 c42ea004 res/raw-de/nodomain.html
10975 Stored 10975 0% 01-15-09 23:16 21dc2fce res/raw/fallbackring.ogg
579 Deflate 282 51% 01-15-09 23:16 11c56b88 res/raw/loaderror.html
890 Deflate 418 53% 01-15-09 23:16 393cf037 res/raw/nodomain.html
25588 Deflate 5051 80% 01-16-09 12:04 cf7826df res/xml-en/autotext.xml
164 Deflate 97 41% 01-16-09 12:04 ee886635 res/xml/apns.xml
116 Deflate 59 49% 01-16-09 12:04 885f246d res/xml/autotext.xml
864 Deflate 312 64% 01-16-09 12:04 65ad9d7e res/xml/preferred_time_zones.xml
61044 Deflate 11755 81% 01-16-09 12:04 0bc79a58 res/xml/time_zones_by_country.xml
747776 Stored 747776 0% 01-16-09 12:04 98f996b3 resources.arsc
-------- ------- --- -------
2246729 1774656 21% 851 files

如果采用-a选项,会在上述文件列表之后,打印出android使用的符号表:

Resource table:
mError=0x0 (Success)
Package Groups (1)
Package Group 0 id=1 packageCount=1 name=android
Package 0 id=1 name=android typeCount=13
type 0 configCount=1 entryCount=599
spec resource 0x01010000 android:attr/theme: flags=0x40000000
spec resource 0x01010001 android:attr/label: flags=0x40000000
spec resource 0x01010002 android:attr/icon: flags=0x40000000
spec resource 0x01010003 android:attr/name: flags=0x40000000
spec resource 0x01010004 android:attr/manageSpaceActivity: flags=0x40000000
spec resource 0x01010005 android:attr/allowClearUserData: flags=0x40000000
spec resource 0x01010006 android:attr/permission: flags=0x40000000
spec resource 0x01010007 android:attr/readPermission: flags=0x40000000
spec resource 0x01010008 android:attr/writePermission: flags=0x40000000
spec resource 0x01010009 android:attr/protectionLevel: flags=0x40000000
spec resource 0x0101000a android:attr/permissionGroup: flags=0x40000000
... ...

这些符号表的格式还需要进一步研究才能搞明白 -_-!

使用AAPT打包资源文件

使用以下命令查看android的build系统是如何打包framework-res模块的:

cd ~/android/src
make -n --debug framework-res

以下是从输出提取的关键步骤:

1. 第一步,生成资源apk包,由以下命令完成:

out/host/linux-x86/bin/aapt package -z -u -x  -M frameworks/base/core/res/AndroidManifest.xml -S frameworks/base/core/res/res
-A frameworks/base/core/res/assets -F out/target/product/generic/obj/APPS/framework-res_intermediates/package.apk

2. 第二步,为生成的资源包做签名:

java -jar out/host/linux-x86/framework/signapk.jar build/target/product/security/platform.x509.pem build/target/product/secur
ity/platform.pk8 out/target/product/generic/obj/APPS/framework-res_intermediates/package.apk.unsigned out/target/product/gene
ric/obj/APPS/framework-res_intermediates/package.apk.signed

3. 第三步,为生成的包做对齐处理:

out/host/linux-x86/bin/zipalign -f 4 out/target/product/generic/obj/APPS/framework-res_intermediates/package.apk.unaligned ou
t/target/product/generic/obj/APPS/framework-res_intermediates/package.apk.aligned

如此生成的framework-res.apk包可以被用来替换system.img中的资源包。(在CupCake前的稳定版本中测试可行)

具体步骤:

  1. 首先用生成的framework-res.apk替换在~/android/src/out/target/product/generic/system/framework中的同名文件。
  2. 用make snod生成新的system.img,替换sdk目录下的images/system.img
  3. 用-wipe-date参数启动emulator

使用AAPT解压资源包(.apk)

./aapt d xmltree framework-res.apk res/anim/fade_in.xml
N: android=http://schemas.android.com/apk/res/android
E: alpha (line=21)
A: android:interpolator(0x01010141)=@0x10a0006
A: android:duration(0x01010198)=(type 0x10)0x12c
A: android:fromAlpha(0x010101ca)=(type 0x4)0x0
A: android:toAlpha(0x010101cb)=(type 0x4)0x3f800000
./aapt d xmlstrings framework-res.apk res/anim/fade_in.xml
String #0: interpolator
String #1: fromAlpha
String #2: toAlpha
String #3: duration
String #4: android
String #5: http://schemas.android.com/apk/res/android
String #6:
String #7: alpha

而没有经过编译的文件为:

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@anim/decelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="300" />

相应的R.java文件为:

package com.android.internal;

public final class R {
public static final class anim {
public static final int accelerate_decelerate_interpolator=0x010a0004;
public static final int accelerate_interpolator=0x010a0005;
public static final int app_starting_exit=0x010a0007;
public static final int decelerate_interpolator=0x010a0006;
public static final int dialog_enter=0x010a0008;
public static final int dialog_exit=0x010a0009;
... ...

也可以从符号表中得到这些索引值:

resource 0x010a0006 android:anim/decelerate_interpolator: t=0x03 d=0x00001132 (s=0x0008 r=0x00) (PUBLIC)

配合系统预定的framework/base/core/res/res目录的模版,就可以重建/res文件.

Android aapt 工具介绍(转)的更多相关文章

  1. Android 开发工具介绍-SDK工具和平台工具

    原文链接:http://android.eoe.cn/topic/android_sdk Android的SDK提供各种工具可以帮你为Android平台开发移动应用程序.这些工具被分类成两组:SDK工 ...

  2. Android studio工具介绍

    区域1介绍 这个区域是运行和调试相关的操作. 1.编译2中显示的模块                      2.当前项目的模块列表            3.运行2中显示的模块           ...

  3. 腾讯优测优分享 | Android性能测试工具化实现

    腾讯优测专业的移动云测试平台,自动化测试提供性能测试数据,云真机实时输出性能数据,让测试更简单! 1.Android性能测试介绍 提到Android性能测试,我们总免不了俗地要首先介绍下Android ...

  4. Android SDK目录结构和工具介绍

    Android SDK目录结构和工具介绍是本文要介绍的内容,主要是来了解并学习Android SDK的内容,具体关于Android SDK内容的详解来看本文. AD: Android SDK目录结构和 ...

  5. Android APP压力测试(一)之Monkey工具介绍

    Android APP压力测试(一) 之Monkey工具介绍 前言 本文主要介绍Monkey工具.Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕.滑动. ...

  6. Android系统性能调优工具介绍

    http://blog.csdn.net/innost/article/details/9008691 经作者授权,发表Tieto某青年牛的一篇<程序员>大作. Android系统性能调优 ...

  7. Android开发环境中的概念和工具介绍

    最近学习Android开发,以前使用C/C++多一些,现在再补点Java知识,不管是哪种语言,都不过是一种工具而已,真的学起来,大同小异,无谓优劣.学习Android编程肯定是要先从环境搭建开始,无论 ...

  8. Android性能分析工具介绍

    1. Android系统性能调优工具介绍 http://blog.csdn.net/innost/article/details/9008691 TraceviewSystraceOprofile 2 ...

  9. 第三章Android移植平台工具介绍

    第三章Android移植平台工具介绍 进行 Android 移植的学习并不一定需要一款 Android 手机,但必须要有一款主流的开发板,开发板是用来进行嵌入式系统开发的电路板,包括中央处理器.存储器 ...

随机推荐

  1. sql左右连接的区别

    数据表的连接有: 1.内连接(自然连接): 只有两个表相匹配的行才能在结果集中出现 2.外连接: 包括 (1)左外连接(左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表 ...

  2. GO入门——3. 控制语句

    1 if 条件表达式没有括号 支持一个初始化表达式(可以是并行方式) 左大括号必须和条件语句或else在同一行 支持单行模式 初始化语句中的变量为block级别,同时隐藏外部同名变量 a := 1 i ...

  3. vue实现城市列表选择

    成果展示 最后的成果就是下面所展示的内容,因为gif图没有做,只能截图所展示,接下来,会带着大家一步一步的完成下面功能,脚手架搭建和node安装在本次案例不会讲解,如果了解,可以在我的博客园找到有详细 ...

  4. 利用cygwin创建windows下的crontab定时任务

    要求 必备知识 熟悉基本编程环境搭建. 运行环境 windows 7(64位); Cygwin-1.7.35 下载地址 环境下载 什么是Cygwin Cygwin是一个在windows平台上运行的类U ...

  5. 分布式锁的两种实现方式(基于redis和基于zookeeper)

    先来说说什么是分布式锁,简单来说,分布式锁就是在分布式并发场景中,能够实现多节点的代码同步的一种机制.从实现角度来看,主要有两种方式:基于redis的方式和基于zookeeper的方式,下面分别简单介 ...

  6. Linux添加防火墙、iptables的安装和配置(亲测)

    iptables基础 规则(rules)其实就是网络管理员预定义的条件,规则一般的定义为“如果数据包头符合这样的条件,就这样处理这个数据包”.规则存储在内核空间的信息 包过滤表中,这些规则分别指定了源 ...

  7. php 通过 strtr 方法来替换文本中指定的内容

    通过在文本中指定待替换的内容,如: [{name}] [{age}] 格式可以自己定义, 大概过程: 在文本中定义需要替换的文本内容: 以键值对的方式 组织数据(数组): 用 file_get_con ...

  8. mysql使用pdo简单封装select语句

    最终代码: function pdo_array_query($pdo, $table_name, $data, $fields=array('*')){ //Will contain SQL sni ...

  9. Semaphore 信号量

    一个计数信号量.从概念上讲,信号量维护了一个许可集.如有必要,在许可可用前会阻塞每一个 acquire(),然后再获取该许可.每个 release() 添加一个许可,从而可能释放一个正在阻塞的获取者. ...

  10. Nullable<T>、Nullable、null、?修饰符的区别

    这章我们讨论一下Nullable<T>.Nullable.null.?修饰符的区别 原创文章 Nullable<T>的前世今生 讨论它们之前,我们有必要讨论一下Nullable ...