{"id":9480,"library":"apkutils2","title":"APK Utilities 2","description":"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.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/codeskyblue/apkutils2","tags":["android","apk","mobile security","reverse engineering","parsing","androguard"],"install":[{"cmd":"pip install apkutils2","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for parsing various binary formats within APKs.","package":"protobuf"},{"reason":"Required for parsing ASN.1 structures, particularly in certificates.","package":"pyasn1"},{"reason":"Provides additional ASN.1 modules for certificate parsing.","package":"pyasn1_modules"},{"reason":"Used for command-line interface utilities.","package":"click"},{"reason":"Core dependency for deep APK analysis, including manifest, resources, and code analysis.","package":"androguard"}],"imports":[{"note":"apkutils2 is a complete rewrite and has a different API and import path than the older apkutils library.","wrong":"from apkutils import APK","symbol":"APK","correct":"from apkutils2 import APK"}],"quickstart":{"code":"from pathlib import Path\nfrom apkutils2 import APK\n\n# IMPORTANT: Replace \"path/to/your.apk\" with the actual path to an Android APK file.\n# You must have a valid .apk file to run this example.\napk_file_path = Path(\"path/to/your.apk\") # e.g., Path(\"/home/user/my_app.apk\")\n\ntry:\n    if not apk_file_path.exists():\n        raise FileNotFoundError(f\"APK file not found: {apk_file_path}. \"\n                                \"Please update 'apk_file_path' to a valid APK file.\")\n\n    apk = APK(str(apk_file_path)) # The constructor expects a string path\n\n    print(f\"Package Name: {apk.package_name}\")\n    print(f\"Version Name: {apk.version_name}\")\n    print(f\"Version Code: {apk.version_code}\")\n    print(f\"Min SDK Version: {apk.get_min_sdk_version()}\")\n\n    # To get the full manifest XML:\n    manifest_xml = apk.get_manifest().toprettyxml()\n    print(\"\\nManifest (first 200 chars):\")\n    print(manifest_xml[:200] + \"...\")\n\n    # Example of getting certificate information\n    certs = apk.get_certs()\n    if certs:\n        cert = certs[0] # Get the first certificate\n        print(f\"\\nCertificate Subject: {cert.get_subject()}\")\n        print(f\"Certificate Issuer: {cert.get_issuer()}\")\n    else:\n        print(\"\\nNo certificates found.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure you have a valid APK file at the specified path.\")","lang":"python","description":"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."},"warnings":[{"fix":"Rewrite code to use `apkutils2`'s new API and ensure imports are `from apkutils2 import APK`.","message":"apkutils2 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`.","severity":"breaking","affected_versions":"All versions of apkutils2 compared to apkutils."},{"fix":"Always verify that the path provided to `APK()` points to a legitimate `.apk` file that your program has read access to.","message":"The `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.","severity":"gotcha","affected_versions":"All"},{"fix":"If `apkutils2` installation or execution fails, specifically investigate `androguard`'s documentation for system-level dependencies or compatibility notes, and try installing `androguard` directly first.","message":"apkutils2 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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure the path passed to `APK()` is correct and points to an existing `.apk` file. Use an absolute path or verify the current working directory.","cause":"The APK file path provided to the `APK()` constructor does not exist on the file system.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'non_existent.apk'"},{"fix":"Verify that the file at the given path is a legitimate, uncorrupted APK file. Try opening it with a standard ZIP utility if unsure.","cause":"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.","error":"zipfile.BadZipFile: File is not a zip file"},{"fix":"If 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.","cause":"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.","error":"ImportError: cannot import name 'APK' from 'apkutils'"}]}