Retrieving Application Version Name in Android Using ADB

Retrieving Application Version Name in Android Using ADB

22 April 2024 Stephan Petzl Leave a comment Tech-Help

When working with Android devices, it’s often necessary to know the version name of an application for purposes like debugging, documentation, or version comparison. The Android Debug Bridge (ADB) provides a straightforward way to retrieve this information without needing to install third-party tools or access the device directly. In this guide, we will cover the steps to find the version name of an application using ADB commands.

Using ADB to Find the Version Name

The most efficient method to get the version name of an application is by using the dumpsys command, which provides information about system services. The specific command to get an application’s version name is:

adb shell dumpsys package my.package | grep versionName

Replace my.package with the actual package name of the application you’re interested in. This command will return the version name directly, allowing for quick and easy access.

Getting All Package Versions

If you need to retrieve version names for all installed applications, a slightly more complex command can be used. This command loops through all packages and prints out their version names:

for p in `adb shell pm list package | awk -F"package:" '{print $2}'`; do echo -n "$p: "; adb shell dumpsys package $p | grep -i versionName | awk -F"=" '{print $2}'; done

This one-liner is particularly useful when you need to compare versions of multiple applications.

Extracting APK Version Without Installation

In scenarios where you have an APK file and you want to know its version without installing it on a device, you can use the Android Asset Packaging Tool (AAPT) included in the Android SDK:

$ANDROID_HOME/build-tools/28.0.3/aapt dump badging path/to/your/app.apk

This command will output various information about the APK, including the version name.

Advanced Version Retrieval

For a more detailed output, including both the versionCode and versionName for different installed versions or flavors of your package, you can use a combination of awk and grep commands:

adb shell dumpsys package | 
awk '/^[ ]*Package \[.*\] (.*)/ { i = index($0, "[") + 1; pkg = substr($0, i, index($0, "]") - i); printf "\n%s", pkg; } /[ ]*versionName=/ { { printf "\t%s", $0; } }  /[ ]*versionCode=/ { { printf  "\t%s", $0; } } ' | 
grep my.package

This script will produce a neatly formatted list of your application’s package names along with their respective version codes and names.

Integrating with Test Automation

Knowing the version name of your application is crucial when automating tests to ensure compatibility and functionality across different versions. Repeato, our no-code test automation tool, can assist with this by allowing you to create, run, and maintain automated tests for your Android and iOS applications. With its fast editing and execution of tests, Repeato leverages computer vision and AI to work with all sorts of app frameworks, including React Native, Flutter, and Unity.

Furthermore, Repeato comes with ADB on board, which means that you can execute ADB commands via script steps within the tool itself, streamlining your testing process and making it easier to manage different application versions and their compatibility with your tests.

Conclusion

Utilizing ADB to retrieve the version name of an Android application is a simple yet powerful method that can be essential for developers and testers alike. By incorporating these techniques into your workflow, you can ensure that your applications are properly versioned and tested, which in turn helps maintain a high standard of quality for your product.

Like this article? there’s more where that came from!