APK Utilities 2

1.0.0 · active · verified Fri Apr 17

apkutils2 is a Python library designed for parsing and analyzing Android Package (APK) files. It offers functionalities to extract manifest information, package details, certificate data, and other resources. This library is a complete rewrite of the original `apkutils` and is currently at version 1.0.0, with an infrequent release cadence focusing on stability.

Common errors

Warnings

Install

Imports

Quickstart

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.")

view raw JSON →