Search code examples
javaseleniumappiumappium-android

Selenium - Obtain app version from .apk files


I am running Android tests using Selenium and Appium. Would like to know how to programmatically obtain the Android app version given then .apk file. OR, if this info could be obtained through Appium that would work as well?


Solution

  • There is one java library which You can import as one of Your dependencies in java and you can check it out on:

    https://github.com/hsiafan/apk-parser

    import it as one of dependencies and usage is really simple just:

    try (ApkFile apkFile = new ApkFile(new File(filePath))) {
        ApkMeta apkMeta = apkFile.getApkMeta();
        System.out.println(apkMeta.getLabel());
        System.out.println(apkMeta.getPackageName());
        System.out.println(apkMeta.getVersionCode());
        for (UseFeature feature : apkMeta.getUsesFeatures()) {
            System.out.println(feature.getName());
        }
    }
    

    From apkMeta You can get sort of info.

    I've used this for a while and found out this doesn't benefit me much so discard it, didn't want additional dependency.

    But this is how You can do it programatically.