File: README.md

package info (click to toggle)
apk-parser 2.6.10%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 996 kB
  • sloc: java: 7,397; xml: 167; makefile: 2
file content (106 lines) | stat: -rw-r--r-- 3,343 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
APK parser lib, for decoding binary XML files, getting APK meta info.

Table of Contents
=================

* [Features](#features)
* [Get APK-parser](#get-apk-parser)
* [Usage](#usage)
    * [1. APK Info](#1-apk-info)
    * [2. Get Binary XML and Manifest XML Files](#2-get-binary-xml-and-manifest-xml-file)
    * [3. Get DEX Classes](#3-get-dex-classes)
    * [4. Get APK Signing Info](#4-get-apk-sign-info)
    * [5. Locales](#5-locales)
* [Reporting Issues](#open-issue)

#### Features

* Retrieve APK meta info, such as title, icon, package name, version, etc.
* Parse and convert binary XML files to text 
* Get classes from DEX files
* Get APK singer info

#### Get APK-parser

Get APK-parser from the Maven Central Reposotiry:
```xml
<dependency>
    <groupId>net.dongliu</groupId>
    <artifactId>apk-parser</artifactId>
    <version>2.6.10</version>
</dependency>
```
From version 2.0, apk-parser requires Java 7. The last version to support Java 6 is 1.7.4.

#### Usage

The ordinary way is using the ApkFile class, which contains convenient methods to get AndroidManifest.xml, APK info, etc.
The ApkFile need to be closed when no longer used. 
There is also a ByteArrayApkFile class for reading APK files from byte array.

##### 1. APK Info

ApkMeta contains name(label), packageName, version, SDK, used features, etc.

```java
try (ApkFile apkFile = new ApkFile(new File(filePath))) {
    ApkMeta apkMeta = apkFile.getApkMeta();
    System.out.println(apkMeta.getLabel());
    System.out.println(apkMeta.getPackageName());
    System.out.println(apkMeta.getVersionCode());
    for (UseFeature feature : apkMeta.getUsesFeatures()) {
        System.out.println(feature.getName());
    }
}
```
##### 2. Get Binary XML and Manifest XML Files

```java
try (ApkFile apkFile = new ApkFile(new File(filePath))) {
    String manifestXml = apkFile.getManifestXml();
    String xml = apkFile.transBinaryXml("res/menu/main.xml");
}
```

##### 3. Get DEX Classes

```java
try(ApkFile apkFile = new ApkFile(new File(filePath))) {
    DexClass[] classes = apkFile.getDexClasses();
    for (DexClass dexClass : classes) {
        System.out.println(dexClass);
    }
}
```

##### 4. Get APK Signing Info

Get the APK signer certificate info and other messages, using:

```java
try(ApkFile apkFile = new ApkFile(new File(filePath))) {
    List<ApkSigner> signers = apkFile.getApkSingers(); // apk v1 signers
    List<ApkV2Signer> v2signers = apkFile.getApkV2Singers(); // apk v2 signers
}
```

##### 5. Locales

An APK may have different info (title, icon, etc.) for different regions and languages——or we can call it a "locale".
If a locale is not set, the default "en_US" locale (<code>Locale.US</code>) is used. You can set a preferred locale by:

```java
try (ApkFile apkFile = new ApkFile(new File(filePath))) {
    apkFile.setPreferredLocale(Locale.SIMPLIFIED_CHINESE);
    ApkMeta apkMeta = apkFile.getApkMeta();
}
```

APK-parser will find the best matching languages for the locale you specified.

If locale is set to null, ApkFile will not translate the resource tag, and instead just give the resource ID.
For example, the title will be something like '@string/app_name' instead of the real name.


#### Reporting Issues
If this parser has any problem with a specific APK, open a new issue, **with a link to download the APK file**.