文章目录
  1. 1. aapt v
  2. 2. aapt l[ist] …
  3. 3. aapt d[ump] …
  4. 4. aapt p[ackage] …
  5. 5. aapt r[emove] …
  6. 6. aapt a[dd] …
  7. 7. appt c[runch] …
  8. 8. aapt s[ingleCrunch] …
  9. 9. 分享与支持

来源:JiongBull’s Blog
微博:@JiongBull
GitHub:JiongBull

Android Asset Packaging Tool,可以查看、创建、更新或删除归档文件(zip、jar或apk),可以将资源文件编译成二进制文件。

aapt v

显示aapt版本号。

1
2
2|root@shamu:/ # aapt v
Android Asset Packaging Tool, v0.2-0ec622cc9f

aapt l[ist] …

aapt l[ist] [-v] [-a] file.{zip,jar,apk},列出归档文件内容。

  • -v 以table形式显示
  • -a 额外显示AndroidManifest.xml内容
  1. aapt l /data/app/com.zhihu.android-2/base.apk

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    root@shamu:/ # aapt l /data/app/com.zhihu.android-2/base.apk
    AndroidManifest.xml
    assets/crashlytics-build.properties
    assets/drawable-hdpi/ic_com_sina_weibo_sdk_close.png
    assets/drawable-ldpi/ic_com_sina_weibo_sdk_close.png
    assets/drawable-mdpi/ic_com_sina_weibo_sdk_close.png
    assets/drawable-xhdpi/ic_com_sina_weibo_sdk_close.png
    assets/drawable-xxhdpi/ic_com_sina_weibo_sdk_close.png
    assets/drawable/weibosdk_dialog_bg.9.png
    ...
  2. aapt l -v /data/app/com.zhihu.android-2/base.apk

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    root@shamu:/ # aapt l -v /data/app/com.zhihu.android-2/base.apk
    Archive: /data/app/com.zhihu.android-2/base.apk
    Length Method Size Ratio Offset Date Time CRC-32 Name
    -------- ------ ------- ----- ------- ---- ---- ------ ----
    15856 Deflate 3343 79% 0 03-31-16 19:28 9304d664 AndroidManifest.xml
    338 Deflate 266 21% 3396 03-31-16 19:28 416243b9 assets/crashlytics-build.properties
    2054 Stored 2054 0% 3727 03-31-16 19:26 be9fc2e4 assets/drawable-hdpi/ic_com_sina_weibo_sdk_close.png
    869 Stored 869 0% 5865 03-31-16 19:26 fb4127df assets/drawable-ldpi/ic_com_sina_weibo_sdk_close.png
    1387 Stored 1387 0% 6816 03-31-16 19:26 055b26ac assets/drawable-mdpi/ic_com_sina_weibo_sdk_close.png
    2971 Stored 2971 0% 8286 03-31-16 19:26 fd14d699 assets/drawable-xhdpi/ic_com_sina_weibo_sdk_close.png
    4162 Stored 4162 0% 11342 03-31-16 19:26 65f5bfc5 assets/drawable-xxhdpi/ic_com_sina_weibo_sdk_close.png
    495 Stored 495 0% 15589 03-31-16 19:26 0dfdb02b assets/drawable/weibosdk_dialog_bg.9.png
    ...
  3. aapt l -a /data/app/com.zhihu.android-2/base.apk

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    ...
    Android manifest:
    N: android=http://schemas.android.com/apk/res/android
    E: manifest (line=15)
    A: android:versionCode(0x0101021b)=(type 0x10)0x133
    A: android:versionName(0x0101021c)="3.2.0" (Raw: "3.2.0")
    A: package="com.zhihu.android" (Raw: "com.zhihu.android")
    A: platformBuildVersionCode=(type 0x10)0x17 (Raw: "23")
    A: platformBuildVersionName="6.0-2438415" (Raw: "6.0-2438415")
    E: uses-sdk (line=20)
    A: android:minSdkVersion(0x0101020c)=(type 0x10)0xf
    A: android:targetSdkVersion(0x01010270)=(type 0x10)0x17
    E: uses-permission (line=30)
    A: android:name(0x01010003)="android.permission.READ_EXTERNAL_STORAGE" (Raw: "android.permission.READ_EXTERNAL_STORAGE")
    E: uses-permission (line=31)
    A: android:name(0x01010003)="android.permission.WRITE_EXTERNAL_STORAGE" (Raw: "android.permission.WRITE_EXTERNAL_STORAGE")
    ...

aapt d[ump] …

aapt d[ump] [--values] [--include-meta-data] WHAT file.{apk} [asset [asset ...]],输出APK内的一些信息。

  • strings 显示APK中资源表字符常量池里的内容
  • badging 显示APK中声明的应用的标签、图标和相关描述
  • permissions 显示APK的权限
  • resources 显示APK的资源表
  • configurations 显示APK的配置信息
  • xmltree 以树形结构显示指定资产编译后的XML资源
  • xmlstrings 显示指定的编译后的XML资产里所有字符串
  1. aapt d strings /data/app/com.zhihu.android-2/base.apk

    1
    2
    3
    4
    5
    6
    7
    2|root@shamu:/ # apt d strings /data/app/com.zhihu.android-2/base.apk
    String pool of 6140 unique UTF-8 non-sorted strings, 6140 entries and 1 styles using 313704 bytes:
    String #0: Requested by %1$s
    String #1: Requested by %1$s
    String #2: Requested by %1$s
    String #3: res/menu/question_edit.xml
    ...
  2. aapt d badging /data/app/com.zhihu.android-2/base.apk

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    2|root@shamu:/ # aapt d badging /data/app/com.zhihu.android-2/base.apk
    package: name='com.zhihu.android' versionCode='307' versionName='3.2.0' platformBuildVersionName='6.0-2438415'
    sdkVersion:'15'
    targetSdkVersion:'23'
    uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
    uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
    uses-permission: name='android.permission.NFC'
    uses-permission: name='android.permission.RECEIVE_BOOT_COMPLETED'
    uses-permission: name='android.permission.DOWNLOAD_WITHOUT_NOTIFICATION'
    uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
    uses-permission: name='android.permission.INTERNET'
    uses-permission: name='android.permission.ACCESS_WIFI_STATE'
    application-label:'知乎'
    ...
    application-icon-120:'res/mipmap-mdpi-v4/ic_launcher.png'
    application-icon-160:'res/mipmap-mdpi-v4/ic_launcher.png'
    application-icon-213:'res/mipmap-hdpi-v4/ic_launcher.png'
    application-icon-240:'res/mipmap-hdpi-v4/ic_launcher.png'
    ...
  3. aapt d permissions /data/app/com.zhihu.android-2/base.apk

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    2|root@shamu:/ # aapt d permissions /data/app/com.zhihu.android-2/base.apk
    package: com.zhihu.android
    uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
    uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
    uses-permission: name='android.permission.NFC'
    uses-permission: name='android.permission.RECEIVE_BOOT_COMPLETED'
    uses-permission: name='android.permission.DOWNLOAD_WITHOUT_NOTIFICATION'
    uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
    uses-permission: name='android.permission.INTERNET'
    uses-permission: name='android.permission.ACCESS_WIFI_STATE'
  4. aapt d resources /data/app/com.zhihu.android-2/base.apk

    1
    2
    2|root@shamu:/ # aapt d resources /data/app/com.zhihu.android-2/base.apk
    竟然无输出结果
  5. aapt d configurations /data/app/com.zhihu.android-2/base.apk

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    anydpi-v21
    nodpi-v4
    v21
    v23
    ldpi-v4
    mdpi-v4
    ldrtl-mdpi-v17
    tvdpi-v4
    hdpi-v4
    ldrtl-hdpi-v17
    xhdpi-v4
    ldrtl-xhdpi-v17
    xxhdpi-v4
    ldrtl-xxhdpi-v17
    xxxhdpi-v4
    ldrtl-xxxhdpi-v17
    xxxhdpi-v21
    ...
  6. aapt d xmltree /data/app/com.zhihu.android-2/base.apk res/menu/question_edit.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    N: android=http://schemas.android.com/apk/res/android
    N: app=http://schemas.android.com/apk/res-auto
    E: menu (line=3)
    E: item (line=6)
    A: android:id(0x010100d0)=@0x7f100258
    A: android:title(0x010101e1)=@0x7f090062
    A: app:showAsAction(0x7f0101ef)=(type 0x11)0x1
    E: item (line=11)
    A: android:icon(0x01010002)=@0x7f02009b
    A: android:id(0x010100d0)=@0x7f100278
    A: android:title(0x010101e1)=@0x7f090055
    A: app:showAsAction(0x7f0101ef)=(type 0x11)0x1
    E: item (line=17)
    A: android:icon(0x01010002)=@0x7f02009c
    A: android:id(0x010100d0)=@0x7f100259
    A: android:title(0x010101e1)=@0x7f09005c
    A: app:showAsAction(0x7f0101ef)=(type 0x11)0x1
  7. aapt d xmlstrings /data/app/com.zhihu.android-2/base.apk res/menu/question_edit.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    String pool of 11 unique UTF-8 non-sorted strings, 11 entries and 0 styles using 228 bytes:
    String #0: id
    String #1: title
    String #2: showAsAction
    String #3: icon
    String #4: android
    String #5: http://schemas.android.com/apk/res/android
    String #6:
    String #7: app
    String #8: http://schemas.android.com/apk/res-auto
    String #9: menu
    String #10: item

aapt p[ackage] …

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
aapt p[ackage] [-d][-f][-m][-u][-v][-x[ extending-resource-id]][-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-density DENSITY] \
[--split CONFIGS [--split CONFIGS]] \
[--feature-of package [--feature-after package]] \
[raw-files-dir [raw-files-dir] ...] \
[--output-text-symbols DIR]

打包Android资源。它将读取通过-M-A-Sraw-files-dir参数指定的资产和资源。-J-P-F-R选项控制输出哪些文件。

aapt r[emove] …

aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...],移除归档文件中指定的文件。

  1. aapt r /data/app/com.jiongbull.art.note-1/base.apk res/layout/activity_g.xml

    1
    127|root@shamu:/ # aapt r /data/app/com.jiongbull.art.note-1/base.apk res/layout/activity_g.xml                         <
  2. aapt r -v /data/app/com.jiongbull.art.note-1/base.apk res/layout/activity_g.xml

    1
    127|root@shamu:/ # aapt r -v /data/app/com.jiongbull.art.note-1/base.apk res/layout/activity_b.xml

aapt a[dd] …

aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...],把指定的文件添加到归档文件中。

aapt a -v /data/app/com.jiongbull.art.note-1/base.apk /storage/emulated/0/deviceid.txt

1
127|root@shamu:/ # aapt a -v /data/app/com.jiongbull.art.note-1/base.apk /storage/emulated/0/deviceid.txt /storage/emulated/0/deviceid.txt

appt c[runch] …

aapt c[runch] [-v] -S resource-sources ... -C output-folder ...,对在一个或多个资源文件夹里的PNG文件进行预处理并保存到指定的文件夹中。

aapt c -S input -C output

1
2
3
root@shamu:/storage/emulated/0 # aapt c -S input -C output
Crunching PNG Files in source dir: input
To destination dir: output

aapt s[ingleCrunch] …

aapt s[ingleCrunch] [-v] -i input-file -o outputfile,对单一PNG文件进行预处理。

aapt s -v -i logo.png -o output/logo.png

1
2
3
4
139|root@shamu:/storage/emulated/0 # aapt s -v -i logo.png -o output/logo.png
Crunching single PNG file: logo.png
Output file: output/logo.png
Processing image to cache: logo.png => output/logo.png

分享与支持

  • 如果这篇文章对你有帮助,请分享下面的链接让更多人受益。
  • 更多支持,请点这里
文章目录
  1. 1. aapt v
  2. 2. aapt l[ist] …
  3. 3. aapt d[ump] …
  4. 4. aapt p[ackage] …
  5. 5. aapt r[emove] …
  6. 6. aapt a[dd] …
  7. 7. appt c[runch] …
  8. 8. aapt s[ingleCrunch] …
  9. 9. 分享与支持