Android apkanalyzer - 安卓APK分析器用法(分析APK的manifest,resource, apk大小,版本信息)

原文:https://developer.android.com/studio/command-line/apkanalyzer

Android sdk中提供了一个非常实用的tool - apkanalyzer, 该tool的路径是android_sdk/tools/bin/apkanalyzer

注意:该tool无法直接在window上运行,请下载安装git for windows: https://gitforwindows.org/, 并启动git bash


当然你也可以用Android Studio 工具:Analyze Your Build with APK Analyzer.

apkanalyzer用法

 
apkanalyzer [ global-options ] subject verb [ options ] apk-file [ apk-file2 ]

global-options是可选参数,后面再介绍。

subject参数用于指定你想要查询整个apk还是部分apk的信息,其取值可以是:

  • apk: 分析APK文件的属性,比如application ID, version code, and version name.
  • files: 分析APK文件里面的文件.
  • manifest: 分析APK文件里面的manifest.(注:这是我目前用的比较多的参数,之前是用AXMLPrinter2.jar)
  • dex: 分析APK之中的dex文件.
  • resources: 查看resource信息.

The verb is what you want to know about the subject. The subjects, verbs, and their options are described in Commands.

verb参数必须和subject结合使用。一般情况下我们只能指定分析一个apk文件,但是使用apk compare参数时,我们需要指定第二个apk文件。另外--human-readable可以简写成-h, 示例:

 
apkanalyzer - h apk file - size myapk . apk

Global options

OptionDescription
--human-readablePrints sizes in human-readable format.

常见用法

下面给出一些常见的用法

View APK file attributesDescription
apk summary apk-filePrints the application ID, version code, and version name.

Example output:

 
     
com.myapp 5 1.1-beta
apk file-size apk-filePrints the total file size of the APK.
apk download-sizeapk-filePrints an estimate of the download size of the APK.
apk features [--not-required] apk-filePrints features used by the APK that trigger Play Store filtering . Add the --not-required option to include features marked as not required in the output.

Example output:

 
     
android.hardware.type.watch android.hardware.microphone implied: requested android.permission.RECORD_AUDIO permission
apk compare [optionsapk-fileapk-file2Compares the sizes of apk-file and apk-file2. You can include the following options:
  • --different-only: Print directories and files with differences.
  • --files-only: Do not print directory entries.
  • --patch-size: Show an estimate of the file-by-file patch instead of a raw difference.

Example output (old size / new size / size difference / path):

 
     
39086736 48855615 9768879 / 10678448 11039232 360784 /classes.dex 18968956 18968956 0 /lib/ 110576 110100 -476 /AndroidManifest.xml ...
View the APK file systemDescription
files list apk-fileLists all files in the APK.

Example output:

 
     
/ /classes2.dex /classes.dex /assets/ /assets/asset.data /AndroidManifest.xml /resources.arsc /res/ ...
files cat --filepath apk-filePrints out the file contents. You must specify a path inside the APK using the --file path option, such as --file /AndroidManifest.xml
View information in the manifestDescription
manifest print apk-filePrints the APK manifest in XML format.
manifest application-id apk-filePrints the application ID value.
manifest version-name apk-filePrints the version name value.
manifest version-code apk-filePrints the version code value.
manifest min-sdkapk-filePrints the minimum SDK version.
manifest target-sdkapk-filePrints the target SDK version.
manifest permissionsapk-filePrints the list of permissions.
manifest debuggableapk-filePrints whether the app is debuggable.
Access DEX file informationDescription
dex list apk-filePrints a list of the DEX files in the APK.
dex references [--files path] [--filespath2apk-filePrints the number of method references in the specified DEX files. The default is all DEX files. Add the --files option to indicate specific files that you want to include.

Example output:

 
     
classes.dex 59598 classes2.dex 8042
dex packages [option1 option2 ...apk-filePrints the class tree from DEX. In the output, PCM, and F indicate packages, classes, methods, and fields, respectively. And xkr, and d indicate removed, kept, referenced and defined nodes, respectively.

Add the following options to refine the output:

  • --defined-only: Include only classes defined in the APK in the output.
  • --files: Specify the DEX file names to include. Default: all DEX files.
  • --proguard-folder file: Specify the Proguard output folder to search for mappings.
  • --proguard-mappings file: Specify the Proguard mappings file.
  • --proguard-seeds file: Specify the Proguard seeds file.
  • --proguard-usages file: Specify the Proguard usages file.
  • --show-removed: Show classes and members that were removed by Proguard.

Example output (type / state / defined methods / referenced methods / byte size / name):

 
     
P d 1 1 85 g P d 1 1 85 g.a C d 1 1 85 g.a.a M d 1 1 45 g.a.a java.lang.Object get() C r 0 1 40 byte[] M r 0 1 40 byte[] java.lang.Object clone()
dex code --classclass [--methodmethod]Prints the bytecode of a class or method in smali format. The class name is required and prints the fully qualified class name to decompile. Add the --method option to specify the method to decompile. The format for the method decompile is name(params)returnType, for example, someMethod(Ljava/lang/String;I)V.
View resources stored in res/ and resources.arscDescription
resources packagesPrints a list of the packages that are defined in the resources table.
resources configs --type type [--packagepackageapk-filePrints a list of configurations for the specified type. The type is a resource type such as string. Include the --packageoption if you want to specify the resource table package name, otherwise the first defined package will be used.
resources value --config config --namename --type type [--package package]apk-filePrints the value of the resource specified by configname, and type. The type option is the type of the resource, such asstring. Include the --package option if you want to specify the resource table package name, otherwise the first defined package will be used.
resources names --config config --typetype [--packagepackageapk-filePrints a list of resource names for a configuration and type. The type option is the type of the resource, such as string. Include the --package option if you want to specify the resource table package name, otherwise the first defined package will be used.
resources xml --filepath apk-filePrints the human-readable form

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值