xref: /aosp_15_r20/tools/apksig/README.md (revision 7bbbfb8d33ab710321c31da7a57038ad95607045)
1*7bbbfb8dSAndroid Build Coastguard Worker# apksig
2*7bbbfb8dSAndroid Build Coastguard Worker
3*7bbbfb8dSAndroid Build Coastguard Workerapksig is a project which aims to simplify APK signing and checking whether APK signatures are
4*7bbbfb8dSAndroid Build Coastguard Workerexpected to verify on Android. apksig supports
5*7bbbfb8dSAndroid Build Coastguard Worker[JAR signing](https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Signed_JAR_File)
6*7bbbfb8dSAndroid Build Coastguard Worker(used by Android since day one) and
7*7bbbfb8dSAndroid Build Coastguard Worker[APK Signature Scheme v2](https://source.android.com/security/apksigning/v2.html) (supported since
8*7bbbfb8dSAndroid Build Coastguard WorkerAndroid Nougat, API Level 24). apksig is meant to be used outside of Android devices.
9*7bbbfb8dSAndroid Build Coastguard Worker
10*7bbbfb8dSAndroid Build Coastguard WorkerThe key feature of apksig is that it knows about differences in APK signature verification logic
11*7bbbfb8dSAndroid Build Coastguard Workerbetween different versions of the Android platform. apksig thus thoroughly checks whether an APK's
12*7bbbfb8dSAndroid Build Coastguard Workersignature is expected to verify on all Android platform versions supported by the APK. When signing
13*7bbbfb8dSAndroid Build Coastguard Workeran APK, apksig chooses the most appropriate cryptographic algorithms based on the Android platform
14*7bbbfb8dSAndroid Build Coastguard Workerversions supported by the APK being signed.
15*7bbbfb8dSAndroid Build Coastguard Worker
16*7bbbfb8dSAndroid Build Coastguard WorkerThe project consists of two subprojects:
17*7bbbfb8dSAndroid Build Coastguard Worker
18*7bbbfb8dSAndroid Build Coastguard Worker  * apksig -- a pure Java library, and
19*7bbbfb8dSAndroid Build Coastguard Worker  * apksigner -- a pure Java command-line tool based on the apksig library.
20*7bbbfb8dSAndroid Build Coastguard Worker
21*7bbbfb8dSAndroid Build Coastguard Worker
22*7bbbfb8dSAndroid Build Coastguard Worker## apksig library
23*7bbbfb8dSAndroid Build Coastguard Worker
24*7bbbfb8dSAndroid Build Coastguard Workerapksig library offers three primitives:
25*7bbbfb8dSAndroid Build Coastguard Worker
26*7bbbfb8dSAndroid Build Coastguard Worker  * `ApkSigner` which signs the provided APK so that it verifies on all Android platform versions
27*7bbbfb8dSAndroid Build Coastguard Worker    supported by the APK. The range of platform versions can be customized.
28*7bbbfb8dSAndroid Build Coastguard Worker  * `ApkVerifier` which checks whether the provided APK is expected to verify on all Android
29*7bbbfb8dSAndroid Build Coastguard Worker    platform versions supported by the APK. The range of platform versions can be customized.
30*7bbbfb8dSAndroid Build Coastguard Worker  * `(Default)ApkSignerEngine` which abstracts away signing APKs from parsing and building APKs.
31*7bbbfb8dSAndroid Build Coastguard Worker    This is useful in optimized APK building pipelines, such as in Android Plugin for Gradle,
32*7bbbfb8dSAndroid Build Coastguard Worker    which need to perform signing while building an APK, instead of after. For simpler use cases
33*7bbbfb8dSAndroid Build Coastguard Worker    where the APK to be signed is available upfront, the `ApkSigner` above is easier to use.
34*7bbbfb8dSAndroid Build Coastguard Worker
35*7bbbfb8dSAndroid Build Coastguard Worker_NOTE: Some public classes of the library are in packages having the word "internal" in their name.
36*7bbbfb8dSAndroid Build Coastguard WorkerThese are not public API of the library. Do not use \*.internal.\* classes directly because these
37*7bbbfb8dSAndroid Build Coastguard Workerclasses may change any time without regard to existing clients outside of `apksig` and `apksigner`._
38*7bbbfb8dSAndroid Build Coastguard Worker
39*7bbbfb8dSAndroid Build Coastguard Worker
40*7bbbfb8dSAndroid Build Coastguard Worker## apksigner command-line tool
41*7bbbfb8dSAndroid Build Coastguard Worker
42*7bbbfb8dSAndroid Build Coastguard Workerapksigner command-line tool offers two operations:
43*7bbbfb8dSAndroid Build Coastguard Worker
44*7bbbfb8dSAndroid Build Coastguard Worker  * sign the provided APK so that it verifies on all Android platforms supported by the APK. Run
45*7bbbfb8dSAndroid Build Coastguard Worker    `apksigner sign` for usage information.
46*7bbbfb8dSAndroid Build Coastguard Worker  * check whether the provided APK's signatures are expected to verify on all Android platforms
47*7bbbfb8dSAndroid Build Coastguard Worker    supported by the APK. Run `apksigner verify` for usage information.
48*7bbbfb8dSAndroid Build Coastguard Worker
49*7bbbfb8dSAndroid Build Coastguard WorkerThe tool determines the range of Android platform versions (API Levels) supported by the APK by
50*7bbbfb8dSAndroid Build Coastguard Workerinspecting the APK's AndroidManifest.xml. This behavior can be overridden by specifying the range
51*7bbbfb8dSAndroid Build Coastguard Workerof platform versions on the command-line.
52