Last active
September 17, 2025 09:20
-
-
Save Anton-V-K/4eb0ae1cda7f32cee9cf460526deb4a5 to your computer and use it in GitHub Desktop.
Python script to check validity of APK-files in a directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # pip install apkutils2 | |
| import os | |
| import sys | |
| from apkutils2 import APK | |
| def check_apk(apk_path): | |
| apk = APK(apk_path) | |
| manifest = apk.get_manifest() | |
| if not manifest: # missing manifest usually means we work with partial APK, which is split | |
| raise Exception("Can't get manifest") | |
| # Retrieve attribute value (string) or None if not present | |
| splits_required_str = manifest.get('@com.android.vending.splits.required') # https://stackoverflow.com/q/56091193/536172 | |
| splits_required = splits_required_str == 'true' if splits_required_str else False | |
| if splits_required: | |
| raise Exception("@com.android.vending.splits.required") | |
| def check_apks_recursively(root_dir): | |
| for dirpath, _, filenames in os.walk(root_dir): | |
| for filename in filenames: | |
| if filename.lower().endswith('.apk'): | |
| apk_path = os.path.join(dirpath, filename) | |
| try: | |
| check_apk(apk_path) | |
| except Exception as ex: | |
| print(f"{apk_path}: {ex}") | |
| if __name__ == "__main__": | |
| if len(sys.argv) < 2: | |
| print(f"Usage: python {os.path.basename(__file__)} <directory>") | |
| sys.exit(1) | |
| root_directory = sys.argv[1] | |
| if not os.path.isdir(root_directory): | |
| print(f"Error: {root_directory} is not a valid directory.") | |
| sys.exit(1) | |
| check_apks_recursively(root_directory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment