原文: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 . apkGlobal options
Option | Description |
---|---|
--human-readable | Prints sizes in human-readable format. |
常见用法
下面给出一些常见的用法
View APK file attributes | Description |
---|---|
apk summary apk-file | Prints the application ID, version code, and version name. Example output: com.myapp 5 1.1-beta |
apk file-size apk-file | Prints the total file size of the APK. |
apk download-sizeapk-file | Prints an estimate of the download size of the APK. |
apk features [--not-required] apk-file | Prints 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 [options] apk-fileapk-file2 | Compares the sizes of apk-file and apk-file2 . You can include the following options:
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 system | Description |
files list apk-file | Lists all files in the APK. Example output: / /classes2.dex /classes.dex /assets/ /assets/asset.data /AndroidManifest.xml /resources.arsc /res/ ... |
files cat --filepath apk-file | Prints 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 manifest | Description |
manifest print apk-file | Prints the APK manifest in XML format. |
manifest application-id apk-file | Prints the application ID value. |
manifest version-name apk-file | Prints the version name value. |
manifest version-code apk-file | Prints the version code value. |
manifest min-sdkapk-file | Prints the minimum SDK version. |
manifest target-sdkapk-file | Prints the target SDK version. |
manifest permissionsapk-file | Prints the list of permissions. |
manifest debuggableapk-file | Prints whether the app is debuggable. |
Access DEX file information | Description |
dex list apk-file | Prints a list of the DEX files in the APK. |
dex references [--files path] [--filespath2] apk-file | Prints 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-file | Prints the class tree from DEX. In the output, P , C , M , and F indicate packages, classes, methods, and fields, respectively. And x , k , r , and d indicate removed, kept, referenced and defined nodes, respectively.Add the following options to refine the output:
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.arsc | Description |
resources packages | Prints a list of the packages that are defined in the resources table. |
resources configs --type type [--packagepackage] apk-file | Prints a list of configurations for the specified type . The type is a resource type 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 value --config config --namename --type type [--package package]apk-file | Prints the value of the resource specified by config , name , 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 [--packagepackage] apk-file | Prints 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-file | Prints the human-readable form |