Android 開發(fā)之 aapt 工具

工具簡介:

  • 在 Android SDK 中带污,有一系列的構(gòu)建工具提岔,其路徑在于:xxx/sdk/build-tools/$versionCode/ 路徑下浓若。其中 $versionCode 為某個構(gòu)建工具的版本皇钞,比如 25.0.1, 25.0.2 或其他版本已日。

aapt 工具的作用:

  • 獲取應(yīng)用中的詳細(xì)信息:aapt dump badging | permissions | resources | configurations | xmltree | xmlstrings xxx.apk
  • android 編譯資源打包資源文件:aapt p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] ...
  • 移除壓縮文件中的目標(biāo)文件:aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]
  • 向壓縮文件中添加目標(biāo)文件:aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]
  • 單資源嘿架、多資源打包:aapt c[runch] [-v] -S resource-sources ... -C output-folder ...
  • 查看當(dāng)前工具版本:aapt v[ersion]

aapt 的配置方式:

  • MAC 電腦:
    推薦使用的終端工具為:Item2瓶珊,在 ~/.zshrc 中添加配置路徑即可。
  • Windows 電腦:
    在系統(tǒng)環(huán)境變量中眶明,添加 aapt 所在路徑即可艰毒,如果本地有多個版本,選擇其中一個即可搜囱。

aapt 配置是否 OK丑瞧?

  • 開啟 item2 或 powershell 程序,輸入 aapt 后回車蜀肘,如果能看到下面的一段代碼提示绊汹,則為配置成功。
Android Asset Packaging Tool

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

 aapt d[ump] [--values] 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] [-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]

   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 c[runch] [-v] -S resource-sources ... -C output-folder ...
   Do PNG preprocessing and store the results in output folder.

 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
   -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 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 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 class
       that does not contain the final value but is used to make reusable compiled
       libraries that need to access resources.
   --error-on-failed-insert
       Forces aapt to return an error if it fails to insert values into the manifest
       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 the
       specified folder.
   --ignore-assets
       Assets to be ignored. Default pattern is:
       !.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~

使用 aapt 工具查看 apk 的信息:

  • 查看apk版本信息命令:
~ aapt dump badging ~/Desktop/test.apk | grep -e 'version'

相應(yīng)的輸出為:

package: name='com.xxx.xxx' versionCode='1' versionName='1.0'
  • 查看apk的權(quán)限聲明:
aapt dump permissions ~/Desktop/test.apk

相關(guān)輸出為:

package: com.xxxx.yyyy
uses-permission: android.permission.DELETE_PACKAGES
uses-permission: android.permission.INTERNET
uses-permission: android.permission.GET_TASKS
...
  • 查看整包信息:
aapt dump badging ~/Desktop/test.apk
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末扮宠,一起剝皮案震驚了整個濱河市西乖,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌坛增,老刑警劉巖获雕,帶你破解...
    沈念sama閱讀 206,013評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異收捣,居然都是意外死亡届案,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,205評論 2 382
  • 文/潘曉璐 我一進(jìn)店門罢艾,熙熙樓的掌柜王于貴愁眉苦臉地迎上來楣颠,“玉大人,你說我怎么就攤上這事咐蚯⊥觯” “怎么了?”我有些...
    開封第一講書人閱讀 152,370評論 0 342
  • 文/不壞的土叔 我叫張陵春锋,是天一觀的道長矫膨。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么豆拨? 我笑而不...
    開封第一講書人閱讀 55,168評論 1 278
  • 正文 為了忘掉前任直奋,我火速辦了婚禮,結(jié)果婚禮上施禾,老公的妹妹穿的比我還像新娘。我一直安慰自己搁胆,他們只是感情好弥搞,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,153評論 5 371
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著渠旁,像睡著了一般攀例。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上顾腊,一...
    開封第一講書人閱讀 48,954評論 1 283
  • 那天粤铭,我揣著相機(jī)與錄音,去河邊找鬼杂靶。 笑死梆惯,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的吗垮。 我是一名探鬼主播垛吗,決...
    沈念sama閱讀 38,271評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼烁登!你這毒婦竟也來了怯屉?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,916評論 0 259
  • 序言:老撾萬榮一對情侶失蹤饵沧,失蹤者是張志新(化名)和其女友劉穎锨络,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體狼牺,經(jīng)...
    沈念sama閱讀 43,382評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡羡儿,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,877評論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了锁右。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片失受。...
    茶點(diǎn)故事閱讀 37,989評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖咏瑟,靈堂內(nèi)的尸體忽然破棺而出拂到,到底是詐尸還是另有隱情,我是刑警寧澤码泞,帶...
    沈念sama閱讀 33,624評論 4 322
  • 正文 年R本政府宣布兄旬,位于F島的核電站,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏领铐。R本人自食惡果不足惜悯森,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,209評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望绪撵。 院中可真熱鬧瓢姻,春花似錦、人聲如沸音诈。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,199評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽细溅。三九已至褥傍,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間喇聊,已是汗流浹背恍风。 一陣腳步聲響...
    開封第一講書人閱讀 31,418評論 1 260
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留誓篱,地道東北人朋贬。 一個月前我還...
    沈念sama閱讀 45,401評論 2 352
  • 正文 我出身青樓,卻偏偏與公主長得像燕鸽,于是被迫代替她去往敵國和親兄世。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,700評論 2 345

推薦閱讀更多精彩內(nèi)容

  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa閱讀 8,849評論 0 6
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,292評論 0 10
  • 親愛的大侄女: 今天是2018年1月1日啊研,從今天開始御滩,你已正式步入18歲的門檻,法律意義上來說党远,你是成年人了削解,從此...
    蓮城隱士閱讀 439評論 0 1
  • 1济似、抱團(tuán)取暖矫废,2、借船過河砰蠢,3蓖扑、借力使力,少費(fèi)力台舱,4律杠、換平臺。這是60多歲的資深美女家玲姐花了50萬學(xué)費(fèi)學(xué)的四句經(jīng)...
    廖君卓閱讀 758評論 2 1
  • 近日,南方少有的寒冷天氣后迎來了溫暖的陽光柜去,這個周末的天氣也特別好灰嫉,午后,全家坐陽臺上嗮太陽嗓奢,溫暖的陽光懶洋洋的灑...
    枝末閱讀 984評論 0 1