Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.343s · 21.4MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 2.7s · import 0.313s · 22MB
19MB installed
● package 19MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
APK
✓ from apkutils2 import APK
✗ from apkutils import APK
apkutils2 is a complete rewrite and has a different API and import path than the older apkutils library.
This quickstart demonstrates how to initialize the APK parser and extract basic information like package name, version, and manifest. It requires a valid APK file to be present at the specified path.
from pathlib import Path
from apkutils2 import APK
# IMPORTANT: Replace "path/to/your.apk" with the actual path to an Android APK file.
# You must have a valid .apk file to run this example.
apk_file_path = Path("path/to/your.apk") # e.g., Path("/home/user/my_app.apk")
try:
if not apk_file_path.exists():
raise FileNotFoundError(f"APK file not found: {apk_file_path}. "
"Please update 'apk_file_path' to a valid APK file.")
apk = APK(str(apk_file_path)) # The constructor expects a string path
print(f"Package Name: {apk.package_name}")
print(f"Version Name: {apk.version_name}")
print(f"Version Code: {apk.version_code}")
print(f"Min SDK Version: {apk.get_min_sdk_version()}")
# To get the full manifest XML:
manifest_xml = apk.get_manifest().toprettyxml()
print("\nManifest (first 200 chars):")
print(manifest_xml[:200] + "...")
# Example of getting certificate information
certs = apk.get_certs()
if certs:
cert = certs[0] # Get the first certificate
print(f"\nCertificate Subject: {cert.get_subject()}")
print(f"Certificate Issuer: {cert.get_issuer()}")
else:
print("\nNo certificates found.")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure you have a valid APK file at the specified path.")
Debug
Known issues
breakingapkutils2 is a complete rewrite and not an incremental upgrade from the original `apkutils` library. Existing code relying on `apkutils`'s API will not work with `apkutils2`.fixRewrite code to use `apkutils2`'s new API and ensure imports are `from apkutils2 import APK`.
affects: All versions of apkutils2 compared to apkutils.
gotchaThe `APK()` constructor expects a valid path to an actual, readable APK file. Passing a non-existent path or a non-APK file (e.g., an empty file or a text file) will lead to `FileNotFoundError`, `zipfile.BadZipFile`, or other parsing errors.fixAlways verify that the path provided to `APK()` points to a legitimate `.apk` file that your program has read access to.
affects: All
gotchaapkutils2 relies heavily on `androguard`, which can have complex dependencies or installation issues, particularly on certain operating systems or Python environments due to its low-level requirements.fixIf `apkutils2` installation or execution fails, specifically investigate `androguard`'s documentation for system-level dependencies or compatibility notes, and try installing `androguard` directly first.
affects: All
Errors
Common errors & fixes
FileNotFoundError: [Errno 2] No such file or directory: 'non_existent.apk'
The APK file path provided to the `APK()` constructor does not exist on the file system.
fixEnsure the path passed to `APK()` is correct and points to an existing `.apk` file. Use an absolute path or verify the current working directory.
zipfile.BadZipFile: File is not a zip file
The file provided to the `APK()` constructor is not a valid ZIP archive (APKs are essentially ZIP files). This usually means the file is corrupted, empty, or not actually an APK.
fixVerify that the file at the given path is a legitimate, uncorrupted APK file. Try opening it with a standard ZIP utility if unsure.
ImportError: cannot import name 'APK' from 'apkutils'
You are attempting to import `APK` from the older `apkutils` library, but `apkutils2` is installed, or `apkutils2` is installed but you're trying to import using the old path.
fixIf you intend to use `apkutils2`, ensure your import statement is `from apkutils2 import APK`. If you need `apkutils`, install that library explicitly (`pip install apkutils`) and use its specific import paths.
Upgrade
Version history
1.0.0latest on PyPI · released Jul 31, 2019
Audit
Dependencies
protobufrequiredUsed for parsing various binary formats within APKs.
pyasn1requiredRequired for parsing ASN.1 structures, particularly in certificates.
pyasn1_modulesrequiredProvides additional ASN.1 modules for certificate parsing.
clickrequiredUsed for command-line interface utilities.
androguardrequiredCore dependency for deep APK analysis, including manifest, resources, and code analysis.